用C语言设计一个程序统计某个班全体学生3门课的考试成绩。要求能输入学生人数,并按编号从小到大的顺序依次输入学生的成绩,再统计出每门课程的全班总分、平均分及每个考生所有考试的总分和平均分。
https://blog.csdn.net/lvhaoye/article/details/77337146
不知道你这个问题是否已经解决, 如果还没有解决的话:(1)计算学生的平均分,并按平均分高低排出名次,打印出姓名。
(2)打印出平均分90分以上和不及格者的名字。
#include <stdio.h>
struct student {
char name[20];
char num[20];
int c_score;
int w_score;
int avg;
};
int main(void) {
int i,j,p;
struct student stu[30];
for ( i = 0; i <30; i++)
{
scanf("%s%s%d%d",&stu[i].name,&stu[i].num,&stu[i].c_score,&stu[i].w_score);
stu[i].avg = (stu[i].c_score + stu[i].w_score) / 2;
}
for ( i = 0; i < 30-1; i++)
{
for ( j = 0; j < 30-i-1; j++)
{
if (stu[j].avg < stu[j + 1].avg) {
struct student k = stu[j];
stu[j] = stu[j+1];
stu[j + 1] = k;
}
}
}
printf("排名:\n");
for ( p = 0; p < 30; p++)
{
printf("%s\n", stu[p].name);
}
printf("90以上:\n");
for (p = 0; p < 30; p++)
{
if (stu[p].avg > 90) {
printf("%s\t", stu[p].name);
}
}
printf("不及格:\n");
for (p = 0; p < 30; p++)
{
if (stu[p].avg < 90) {
printf("%s\t", stu[p].name);
}
}
return 0;
}