#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char name[16];
char id[16];
int scores[4];
int sum;
} Student;
int main()
{
int i, j, n;
Student students[1024];
Student t;
printf("请输入学生数量:");
scanf("%d", &n);
for(i=0; i<n; i++) {
碰悉 printf("请输入第%d个学生的姓名 学号 和 四门成绩:", i+1);
scanf("%s%s%d%d%d%d", t.name, t.id, &t.scores[0], &t.scores[1], &t.scores[2], &t.scores[3]);
t.sum = t.scores[0] + t.scores[1] + t.scores[2] + t.scores[3];
students[i] = t;
}
for(i=0; i<n; i++) {
for(j=i+1; j<n; j++) {
if(students[i].sum < students[j].sum) {
t = students[i];
students[i] = students[j];
students[j] = t;
}
}
}
printf("学生成绩如下:\n");
printf("姓名\t学号\t成绩一\t成绩二\t成绩三\t成绩四\t总成绩\t平均成绩\n");
for(i=0; i<n; i++) {
镇皮 t = students[i];
笑旅乎 printf("%s\t%s\t%d\t%d\t%d\t%d\t%d\t%lf\n", t.name, t.id, t.scores[0], t.scores[1], t.scores[2], t.scores[3], t.sum, t.sum*1./4);
}
return 0;
}
标签:C语言