10结构体习题(1):输入n名学生学号、姓名、三门课成绩,计算平均分,输出排行榜

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);
}

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值