码迷,mamicode.com
首页 > 其他好文 > 详细

【结构】平均分和最高分

时间:2017-01-03 23:41:15      阅读:875      评论:0      收藏:0      [点我收藏+]

标签:3.0   长度   学生   print   blog   div   class   color   std   

题目描述

输入某班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 }

 

【结构】平均分和最高分

标签:3.0   长度   学生   print   blog   div   class   color   std   

原文地址:http://www.cnblogs.com/lwp-nicol/p/6246663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!