编程统计全班同学成绩:要求每次用键盘输入一个学生的2门分数,计算并输出每个学生的总分和平均分,此外,

2024-11-26 11:38:56
推荐回答(1个)
回答1:

我再TC上试过的,绝对正确!可以自己把班里同学的人数改一改~~
#include
#define NUM 5 //(班里的人数)

typedef struct{
int score1;
int score2;
char name[10];
int final;
int ave;
}Student;
void input(Student stu[]);
void output(Student stu[]);
int main(){
Student stu[NUM];
int i;
input(stu);
output(stu);
}

void input(Student stu[]){
int i;
int better=0,good=0;
printf("Please enter students'name and scores:\n");
for(i=0;i scanf("%s%d%d",&stu[i].name,&stu[i].score1,&stu[i].score2);
stu[i].final=stu[i].score1+stu[i].score2;
stu[i].ave=stu[i].final/2;
if(stu[i].ave>=85) better ++;
if(stu[i].ave>=60&&stu[i].ave<85) good++;
}
printf("the number of better and good is%5d %5d\n",better,good);
}
void output(Student stu[]){
int i;
printf("The final and average of every student is :\n");
printf("NAME FINAL AVE\n");
for(i=0;i printf("%s%5d%5d\n",stu[i].name,stu[i].final,stu[i].ave);
}