哈尔滨工大附中国际部:C语言编程(高分)

来源:百度文库 编辑:神马品牌网 时间:2024/05/04 14:17:29
题目2:
从键盘输入3名学生的4门课成绩,要求找出4门课平均成绩最高者,并输出。

#include <>
struct stu
{
char name[12];
float score[4];
float aver=0;
}student[4];
main()
{
float sum=0;
int i;
int j;
float max;
for(i=0;i<4;i++)
{
scanf("%s",student[i].name);
for (j=0;j<4;j++)
{
printf("Please enter the %d score",j);
scanf("%f",student[i].score[j]);
student[i].aver+=student[i].score[j];
}
student[i].aver/=4;
}
max=student[0].aver;
for(i=1;i<4;i++)
{
if(student[i].aver>max)
{
max=student[i].aver;
j=i;
}
}
printf("The max one %s\n",student[j].name);
for(i=0;i<4;i++)
{
printf("The scores are %f",student[j].score[i]);
}
printf("\nThe max one is %d,the max aver is %f\n",j,max);

}
不知道到底怎样,可以试试