'136 2022-01-08 14:15 采纳率: 100%
浏览 293
已结题

输入5个学生数据,计算总平均成绩,各自平均分,以及最高的学生数据

输入5个学生数据,计算总平均成绩,以及最高分的学生数据
有5个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生数据(包括学号、姓名、3门课程平均成绩、平均分数)
输入用例
1 A 100 90 80
2 B 90 85 70
3 C 66 79 95
4 D 80 75 99
5 E 97 60 71
输出用例
NO. name score1 score2 score3 average
1 A 100.00 90.00 80.00 90.00
2 B 90.00 85.00 70.00 81.67
3 C 66.00 79.00 95.00 80.00
4 D 80.00 75.00 99.00 84.67
5 E 97.00 60.00 71.00 76.00
average=82.47
The highest score is : student 1,A
his scores are:100.00, 90.00, 80.00,average:90.00.

  • 写回答

1条回答 默认 最新

  • 关注

    如下:

    #include <stdio.h>
    struct student 
    {
        int id;
        char name[20];
        float score[3];
        float ave;
    };
    //从键盘录入5个学生的成绩
    void input(struct student stu[])
    {
        int i;
        for (i=0;i<5;i++)
        {
            //printf("请输入学生%d的学号、姓名、3门课成绩:",i+1);
            scanf("%d %s %f %f %f",&stu[i].id,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
            stu[i].ave = (stu[i].score[0] + stu[i].score[1]+stu[i].score[2])/3.0;
        }
    }
    
    int main()
    {
        int i;
        int maxindex = 0;
        float ave=0;
        struct student stu[5];
        input(stu);
        //计算最高分
        for (i=0;i<5;i++)
        {
            ave += stu[i].ave;
            if(stu[i].ave > stu[maxindex].ave)
                maxindex = i;
        }
        ave /= 5;
        printf("NO. name score1 score2 score3 average\n");
        for (i=0;i<5;i++)
        {
            printf("%d %s %.2f %.2f %.2f %.2f\n",stu[i].id,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave);
        }
        printf("average=%.2f\n",ave);
        printf("The highest score is : student %d,%s\n",stu[maxindex].id,stu[maxindex].name);
        printf("his scores are:%.2f %.2f %.2f,average:%.2f",stu[maxindex].score[0],stu[maxindex].score[1],stu[maxindex].score[2],stu[maxindex].ave);
        return 0;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 1月16日
  • 已采纳回答 1月8日
  • 创建了问题 1月8日

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题