C语言:有10个学生,每个学生的数据包括学号,姓名,3门功课的成绩。从键盘输入10个学生的数据?

C语言:有10个学生,每个学生的数据包括学号,姓名,3门功课的成绩。从键盘输入10个学生的数据,要要求按平均成绩降序显示出所有学生的数据(包括学号,姓名,3门课成绩,平均成绩),并将其写入文本文件result.txt中。

#include<stdio.h>
struct Student
{
char name[100];//名字
char num[100];//学号
double class1;//第一门课成绩
double class2;//第二门课成绩
double class3;//第三门课成绩
};
int main()
{
Student student[100];
for (int i = 0; i < 10; i++)//输入学生信息
{
gets(student[i].name);
getchar();//清空键盘缓冲区
gets(student[i].num);
getchar();
scanf("%lf%lf%lf",&student[i].class1,&student[i].class2,&student[i].class3);
}
for (int j = 0; j < 10; j++)//输出学生信息
{
printf("%s\n%s\n%lf\n",student[j].name,student[j].num,(student[j].class1+student[j].class2+student[j].class3)/3.0);
}
return 0;
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答