學產生績的錄入與輸出

來源:互聯網
上載者:User

標籤:io   ar   for   amp   as   har   資訊   return   class   

#include<stdio.h>/*定義一個學生的結構體,成員變數有名字、學籍號、某一學科的成績。分別從鍵盤讀入兩個學生的資訊。最後再後台輸出誰的成績好就在公告欄裡表彰出來,如果成績相同,那麼就在公告欄中一同顯示出來。*///定義一個結構體類型struct Student {char name[20];//名字char idNum[20];//學籍號float score;};void compare(struct Student stus[],int count);int main() {//定義結構體類型的結構體數組struct Student stu[2];for (int i = 0; i < 2; ++i){printf("請輸入第%d個學生的姓名:\n",i+1);//輸入學生的姓名scanf("%s",stu[i].name);printf("請輸入第%d個學生的學籍號:\n",i+1);//輸入學生的學籍號scanf("%s",stu[i].idNum);printf("請輸入第%d個學生的成績:\n",i+1);//輸入學生的成績scanf("%f",&stu[i].score);}// //講學生的資訊列印// for (int i = 0; i < 2; ++i)// {// struct Student *p = &stu[i];// printf("姓名:%s   學籍號:%s   成績:%.2f\n",p->name,p->idNum,p->score);// }compare(stu,2);return 0;}void compare(struct Student stus[],int count) {float max = 0;struct Student *maxStu;for (int i = 0; i < count; ++i){//取得學生的成績float score = stus[i].score;if (max < score){max = score;maxStu = &stus[i];}}if (stus[0].score == stus[1].score){//講學生的資訊列印for (int i = 0; i < 2; ++i){struct Student *p = &stus[i];printf("姓名:%s   學籍號:%s   成績:%.2f\n",p->name,p->idNum,p->score);}}elseprintf("表彰的學生資訊:名字:%s   學籍號:%s   成績:%.2f\n",maxStu->name,maxStu->idNum,maxStu->score);}

學產生績的錄入與輸出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.