Description
有5个学生,每个学生的数据包括:学号、姓名、三门课成绩,编写程序要求从键盘输入学生们的数据,并输出成绩报表(包括每人的学号,姓名、三门成绩及平均分数),还要求输出平均分在前3名的学生姓名及平均成绩。
Input
输入仅五行,输入5个学生的学号、姓名、三门课成绩,要求数据之间用空格分开
Output
输出仅八行,输出5行的成绩报表(依原来顺序的成绩榜,包括:学号 姓名 三门课成绩 平均分),输出3行的成绩榜(平均成绩最高的三个学生的倒序成绩榜,包括:学号 姓名 三门课成绩 平均分)
Sample Input
01 Li 56 78 67
02 Wang 78 77 60
03 Cheng 88 90 93
04 Jiang 77 99 89
05 Zhao 85 89 96
Sample Output
1 Li 56.00 78.00 67.00 67.00
2 Wang 78.00 77.00 60.00 71.67
3 Cheng 88.00 90.00 93.00 90.33
4 Jiang 77.00 99.00 89.00 88.33
5 Zhao 85.00 89.00 96.00 90.00
3 Cheng 88.00 90.00 93.00 90.33
5 Zhao 85.00 89.00 96.00 90.00
4 Jiang 77.00 99.00 89.00 88.33
#include<stdio.h>
#include<stdlib.h>
#define N 5
#define M 3
struct stud
{
int num[5];
char name[5];
float score[3];
float ave;
};struct stud stu[N];
int main()
{
float aver(int x);
int i;
for(i=0;i<N;i++)
{
scanf("%d%s%f%f%f",stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
stu[i].ave=aver(i);
}
for(i=0;i<5;i++)
printf("%d %s %.2f %.2f %.2f %.2f\n",stu[i].num[0],stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave);
int sortandput();
sortandput();
}
float aver(int x)
{
return (stu[x].score[0]+stu[x].score[1]+stu[x].score[2])/3;
}
int sortandput()
{
int i,j;struct stud k;
for(i=0;i<N-1;i++)
for(j=0;j<N-1-i;j++)
{
if(stu[j].ave<stu[j+1].ave)
{
k=stu[j];stu[j]=stu[j+1];stu[j+1]=k;
}
}
for(i=0;i<M;i++)
printf("%d %s %.2f %.2f %.2f %.2f\n",stu[i].num[0],stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave);
}