//有十个学生,每个学生的数据包括学号,姓名,3门课程的成绩,从键盘输入10个学生的数据,要求输出3门课程的总平均成绩,以及最高分的学生的数据
//包括(学号,姓名,3门课成绩,平均分数)
#include<stdio.h>
#define N 3
#define M 3
//定义结构体
struct Student
{
char num[10];
char name[15];
float score[3];
float aver;
}stu[N];
//定义主函数
int main()
{
int i,j,maxi;
float sum,max,average;
//输入数据
for(i=0;i<N;i++)
{
printf("input scores of student %d:\n",i+1);
printf("NO.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<M;j++)
{
printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
//计算
average = 0;
max = 0;
maxi=0;
for(i=0;i<N;i++)
{
sum = 0;
for(j=0;j<M;j++)
sum+=stu[i].score[j];
stu[i].aver=sum/3.0;
average+=stu[i].aver;
if(sum>max)
{
max=sum;
maxi=i;
}
}
average/=N;
//输出
printf("NO. name score1 score2 score3 average\n");
for(i=0;i<N;i++)
{
printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<M;j++)
printf("%9.2f",stu[i].score[j]);
printf("%8.2f\n",stu[i].aver);
}
printf("average=%5.2f\n",average);
printf("The highest score is :student %s,%s\n",stu[maxi].num,stu[maxi].name);
printf("his scores are:%6.2f,%6.2f,%6.2f,average:%5.2f\n",stu[maxi].score[0],stu[maxi].score[1],
stu[maxi].score[2],stu[maxi].aver);
return 0;
}