帮我解一下这道题,C语言的,谢谢了
1个回答
展开全部
#include<stdio.h>
struct Student{
char id[30],name[20];
double score[4] = {.0},ascore = .0, tscore = .0;
};
void input(Student* stu,int size)
{
for(int i = 0;i<size;++i,++stu){
scanf("%s %s %lf %lf %lf %lf",*stu.id,*stu.name,*stu.score[0],*stu.score[1],*stu.score[2],*stu.score[3]);
}
}
double average(Student* stu,int size)
{
double total_aveg_score = .0;
for(int i = 0;i<size;++i){
stu->tscore =
stu->score[0]+stu->score[1]+stu->score[2]+stu->score[3];
stu->ascore = tscore/4;
total_aveg_score+=stu->tscore;
}
return total_aveg_score/(size*4);
}
Student* maximum(Student* stu,int size)
{
Student* max = stu++;
for(int i = 0;i<size;++i,++stu)
if(stu->tscore>max->tscore)
max = stu;
return max;
}
int main()
{
Student stu[10],*max = NULL;
double ave_tsc = .0;
size_t size = sizeof(stu)/sizeof(Student);
input(stu,size);
ave_tsc = average(stu,size);
max = maximum(stu,size);
printf("NO\tName\tScore1\tScore2\tScore3\tSco"
"re4\tTotal\tAverage\n");
for(int i = 0;i<size;++i)
printf("%s\t%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n"
,stu[i].id,stu[i].name,stu[i].score[0],stu[i].score[1]
,stu[i].score[2],stu[i].score[3],stu[i].tscore,
stu[i].ascore);
printf("The highest score:\n%s\t%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n" ,max->id,max->name,max->score[0],max->score[1]
,max->score[2],max->score[3],max->tscore,max->ascore);
printf("The total average score:%lf\n",ave_tsc);
return 0;
}//需要注释么?= =可能有些小错误,自己改一下吧
追问
需要,谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询