#include
#include
#define N 3
/*288-2.有10个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入10个学生数据,
要求编程输出3门课平均成绩以及总分最高分的学生的数据(包括学号、姓名、3门课的成绩、平均分数)。 /
/ run this program using the console pauser or add your own getch, system("pause") or input loop */
struct student
{
int num;
char name[8];
float score[3];
float sum;
};
struct student stu[N];
struct student max()
{
struct student t;
int i;
t=stu[0];
for(i=0;i<N;i++)
{
if(t.sum<stu[i].sum)
{
t=stu[i];
}
}
return t;
}
int main(int argc, char *argv[])
{
int i;
float sum1=0,sum2=0,sum3=0;
struct student t;
for(i=0;i<N;i++)
{
scanf("%d %s %f %f %f",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
}
for(i=0;i<N;i++)
{
stu[i].sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
sum1+=stu[i].score[0];
sum2+=stu[i].score[1];
sum3+=stu[i].score[2];
}
t=max();
printf("平均成绩:score1 score2 score3\n");
printf("%3f %3f %3f\n",sum1/N,sum2/N,sum3/N);
printf("%3d %s %3.1f %3.1f %3.1f %3.1f",t.num,t.name,t.score[0],t.score[1],t.score[2],t.sum/3);
return 0;
}