结构平均分和最高分
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了结构平均分和最高分相关的知识,希望对你有一定的参考价值。
题目描述
输入某班5位学生的姓名及数学、英语成绩,计算每位学生的平均分;然后输出平均分最高的学生之姓名及数学、英语成绩。
输入要求
输入某班5位学生的姓名及数学、英语成绩。姓名是一个长度不超过19个字符的字符串,成绩用整数表示。
输出要求
输出每名学生的姓名和平均分,平均分用浮点数表示,输出时精确到小数点后1位。
然后输出平均分最高的学生之姓名及数学、英语成绩。
假如输入
aaa 61 88 bbb 63 89 ccc 64 82 ddd 85 66 eee 66 85
应当输出
aaa 74.5 bbb 76.0 ccc 73.0 ddd 75.5 eee 75.5 The max score: bbb 63 89
1 #include<stdio.h> 2 struct student{ 3 char name[20]; 4 int math; 5 int English; 6 float average,sum; 7 }; 8 int main(void) 9 { 10 int i,max; 11 struct student stud[5]; 12 13 for(i=0;i<5;i++){ 14 scanf("%s",&stud[i].name); 15 scanf("%d",&stud[i].math); 16 scanf("%d",&stud[i].English); 17 stud[i].sum=stud[i].math+stud[i].English; 18 stud[i].average =stud[i].sum/2; 19 } 20 for(i=0;i<5;i++) 21 printf("%s %.1f\n",stud[i].name ,stud[i].average); 22 23 max=0; 24 for(i=1;i<5;i++){ 25 if(stud[max].average<stud[i].average) 26 max=i; 27 } 28 printf("The max score: %s %d %d\n",stud[max].name ,stud[max].math ,stud[max].English ); 29 return 0; 30 }
以上是关于结构平均分和最高分的主要内容,如果未能解决你的问题,请参考以下文章