题目描述
输入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 }