題目描述
輸入10個學生的學號、姓名和成績,計算並輸出平均分,再按照從高分到低分的順序輸出他們的信息。
輸入要求
輸入10個學生的學號、姓名和成績。學號和成績用整數表示,姓名是一個長度不超過19個字符的字符串。
輸出要求
輸出平均分,再按照從高分到低分的順序輸出10個學生的信息。
並列分數保持輸入時的順序。
假如輸入
101 aaa 80 102 bbb 90 103 ccc 70 104 ddd 59 105 eee 79 106 fff 61 107 ggg 78 108 hhh 80 109 iii 68 110 jjj 81
應當輸出
The average: 74 The student score: 102 bbb 90 110 jjj 81 101 aaa 80 108 hhh 80 105 eee 79 107 ggg 78 103 ccc 70 109 iii 68 106 fff 61 104 ddd 59
1 #include<stdio.h> 2 struct student{ 3 int num; 4 char name[20]; 5 int score; 6 }; 7 struct student stud[10]; 8 int main() 9 { 10 int i,j,max,sum=0; 11 struct student temp; 12 13 for(i=0;i<10;i++){ 14 scanf("%d",&stud[i].num); 15 scanf("%s",&stud[i].name); 16 scanf("%d",&stud[i].score); 17 sum=sum+stud[i].score ; 18 } 19 for(i=0;i<9;i++) 20 { 21 max=i; 22 for(j=i+1;j<10;j++) 23 if(stud[j].score <stud[max].score) 24 max=j; 25 temp=stud[max]; 26 stud[max]=stud[i]; 27 stud[i]=temp; 28 } 29 30 printf("The average: %d\n",sum/10); 31 printf("The student score:\n"); 32 for(i=9;i>=0;i--) 33 printf("%d %s %d\n",stud[i].num ,stud[i].name ,stud[i].score ); 34 35 return 0; 36 }
