c语言程序题第五题 要求使用调用结构体指针的函数,输出每个学生的成绩

 我来答
百度网友0747097
2015-12-31 · TA获得超过621个赞
知道小有建树答主
回答量:506
采纳率:100%
帮助的人:250万
展开全部
#include<stdio.h>

struct 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:\n");
printf("%s %d %lf %lf %lf %lf\n",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;
}
}
我是按照三门课各输出一次平均成绩来写的,望采纳
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式