#includestruct STUDENT{
double score[3];
double average;
int id;
char name[255];
};
void printScore(struct STUDENT *);
int main()
{
struct STUDENT stu[10];
int i;
for(i=0;i<10;++i)
{
printf("请输入姓名:");
scanf("%s",stu[i].name);
printf("Please input the ID:");
scanf("%d",&stu[i].id);
printf("输入三门成绩,空格分隔");
scanf("%lf%lf%lf",stu[i].score[0],stu[i].score[1],stu[i].score[2]);
stu[i].average=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
}
return 0;
}
void printScore(struct STUDENT *stu)
{
double average=0,sum=0;
int i,j,maxId=0;
for(j=0;j<3;++j)
{
for(i=0;i<10;++i)
{
sum+=stu[i].score[j];
if(stu[i].score[j]>stu[maxId].score[j]) maxId=i;
}
average=sum/10;
printf("The average score of Class %d is:%lf",j,average);
printf("The student who have max score of Class 1 is:");
printf("%s %d %lf %lf %lf %lf",stu[maxId].name,stu[maxId].id,stu[maxId].score[0],stu[maxId].score[1],stu[maxId].score[2],stu[maxId].average);
sum=0;
average=0;
maxId=0;
}
}
我是按照三门课各输出一次平均成绩来写的,望采纳