原题链接:[编程入门]结构体之成绩统计2
解题思路:
注意事项:
参考代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
// 定义学生结构体
typedef struct student
{
char number[50];
char name[50];
int score[3];
} stud;
int main() {
int N;
scanf("%d", &N); // 输入学生数量 N
stud stu[100]; // 声明一个结构体数组,用于存储学生信息,数组大小为100
int totalscore[3] = { 0 }; // 用于存储三门课程的总分,初始值都为0
stud higheststudent; // 用于存储最高分的学生
int highscore = 0; // 用于存储最高分
// 输入学生信息并计算总分
for (int i = 0; i < N; i++)
{
// 输入学生的学号、姓名以及三门课程的成绩
scanf("%s %s %d %d %d", stu[i].number, stu[i].name,
&stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
// 计算各门课程的总分
for (int j = 0; j < 3; j++)
{
totalscore[j] += stu[i].score[j];
}
// 检查是否为最高分
int x = stu[i].score[0] + stu[i].score[1] + stu[i].score[2];
if (x > highscore)
{
highscore = x;
higheststudent = stu[i];
}
}
int ave[3];
// 计算各门课程的平均成绩
for (int i = 0; i < 3; i++)
{
ave[i] = (int)totalscore[i] / N; // 计算平均成绩,强制类型转换为整数
}
// 输出各门课的平均成绩
printf("%d %d %d\n", ave[0], ave[1], ave[2]);
// 输出最高分的学生信息
printf("%s %s %d %d %d", higheststudent.number, higheststudent.name,
higheststudent.score[0], higheststudent.score[1], higheststudent.score[2]);
return 0;
} 0.0分
1 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复