输出每个学生三门课的平均成绩,以及平均分最高分学生数据(包括学号、班级、姓名、三门课成绩,平均分)。 格式见下。(四舍五入保留一位小数)
4
20070008 software1 wangjun 87 84 76
20070001 science1 lanxin 90 84 83
20070007 software2 wuke 94 87 86
20070003 science4 xuede 90 86 87
------------------------------------------------------------
wangjun 82.3
lanxin 85.7
wuke 89.0
xuede 87.7
20070007 software2 wuke 94.0 87.0 86.0 89.0
#include <stdio.h>
#include <string.h>
struct STU
{
int id;
double a;
double b;
double c;
double d;
double e;
double avg;
};
int main()
{
int n;
int i;
scanf("%d",&n);
STU student[1000];
for(i=1;i<=n;i++)
{
scanf("%d %lf %lf %lf %lf %lf",&student[i].id,&student[i].a,&student[i].b,
&student[i].c,&student[i].d,&student[i].e);
student[i].avg=(student[i].a+student[i].b+
student[i].c+student[i].d+student[i].e)/5;
}
for(i=1;i<=n;i++)
{
printf("%d %.0lf %.0lf %.0lf %.0lf %.0lf %.1lf\n",student[i].id,student[i].a,student[i].b,
student[i].c,student[i].d,student[i].e,student[i].avg);
}
float num1=0,num2=0,num3=0,num4=0,num5=0;
for(i=1;i<=n;i++)
{
num1=num1+student[i].a ;
num2=num2+student[i].b ;
num3=num3+student[i].c ;
num4=num4+student[i].d ;
num5=num5+student[i].e ;
}
printf("%.1lf %.1lf %.1lf %.1lf %.1lf\n",num1/n,num2/n,num3/n,num4/n,num5/n);
return 0;
}