【文件属性】:
文件名称:14-上机1-006.c
文件大小:2KB
文件格式:C
更新时间:2022-07-01 15:08:16
C代码
#include
#include
struct student
{
int num;
char classname[20];
char name[20];
float score[3];
float aver;
};
void input(struct student stu[])
{
int i,j;
printf("input student num,name,score:\n");
for(i=0;i<5;i++)
{
printf("NO.:");
scanf("%d",&stu;[i].num);
printf("name:");
scanf("%s",stu[i].name);
printf("classname:");
scanf("%s",stu[i].classname);
for(j=0;j<3;j++)
{
printf("stu[%d].score[%d]:",i,j);
scanf("%f",&stu;[i].score[j]);
}
printf("\n");
}
}
void averagescore(struct student stu[])
{
int i,j,sum=0;
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
sum+=stu[i].score[j];
}
stu[i].aver=sum/3.0;
sum=0;
}
}
int maxaveragescore(struct student stu[])
{
int i,m=0;
for(i=0;i<5;i++)
{
if(stu[i].aver>stu[m].aver)
m=i;
}
return m;
}
int main()
{
int i,maxnum;
struct student stu[20];
int maxaveragescore(struct student stu[]);
input(stu);
averagescore(stu);
maxnum=maxaveragescore(stu);
for(i=0;i<5;i++)
{
printf("五名三门课的平均分为:%5.1f\n",stu[i].aver);
}
printf("平均分最高学生为:num:%d name:%s classname:%s score:%5.1f %5.1f %5.1f\n它的平均分为:%5.1lf\n",stu[maxnum].num,stu[maxnum].name,stu[maxnum].classname,stu[maxnum].score[0],stu[maxnum].score[1],stu[maxnum].score[2],stu[maxnum].aver);
return 0;
}