#include
struct student {
char name[20];
int idnum;
float score[3]; //分别存三科成绩
double total; // 总分
};
struct student * highscore(struct student *s, int n)
{
int i;
struct student * high = s;
for(i = 0; i < n; i++) {
(s+i)->total = (s+i)->score[0] + (s+i)->score[1] + (s+i)->score[2];
if(high->total < (s+i)->total)
high = s+i;
}
return high;
}
main()
{
struct student *s, student[5];
// 录入学生信息
for(s = student; s < student+5; s++) {
printf("输入第%d个学生的信息:\n", s-student+1);
printf("姓名:");
scanf("%s", s->name);
printf("学号:");
scanf("%d", &s->idnum);
printf("语文 数学 英语:\n");
scanf("%f %f %f", &(s->score[0]), &(s->score[1]), &(s->score[2]));
}
// 输出学生信息
printf("\n学生信息\n姓名\t学号\t语文\t数学\t英语\n");
for(s = student; s < student+5; s++)
printf("%s\t%d\t%.1f\t%.1f\t%.1f\n", s->name, s->idnum, s->score[0], s->score[1],s->score[2]);
// 计算学生总分病返回总分最高的学生信息
s = highscore(student, 5);
printf("\n总分最高的学生是:%s,学号:%d\n成绩:语文:%.1f数学:%.1f英语:%.1f总分:%.1f\n", s->name, s->idnum, s->score[0], s->score[1],s->score[2], s->total);
}