2025-03-02 06:38:13
学生成绩,代码如下:
#include<stdio.h>
typedef struct Information
{
char no[20];
char name[25];
int score[3];
double avg;
}INFORMATION, *PINFORMATION;
int main()
{
INFORMATION stu[10];
int i,index = -1, maxsc, j;
for (i = 0; i < 10; ++i){
printf ("请输入第%d个学生的信息(学号 姓名 成绩1 成绩2 成绩3)\n", i+1);
scanf ("%s%s%d%d%d", stu[i].no, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
for (j = 0; j < 3; ++j){
if (index!=-1){
if (maxsc < stu[i].score[j]){
maxsc = stu[i].score[j];
index = i;
}
}
else {
maxsc = stu[i].score[j];
index = i;
}
}
stu[i].avg = (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
}
for (i = 0; i < 10; ++i){
printf ("学号:%s\t姓名:%s\t成绩1:%d\t成绩2:%d\t成绩3:%d\t平均分:%f\n", stu[i].no, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].avg);
}
printf ("最高分学生信息:\n");
printf ("学号:%s\t姓名:%s\t成绩1:%d\t成绩2:%d\t成绩3:%d\t平均分:%f\n", stu[index].no, stu[index].name, stu[index].score[0], stu[index].score[1], stu[index].score[2], stu[index].avg);
return 0;
}