解题思路:
进行三个函数的编写
分离功能:一个输出函数,一个求平均数函数,一个找最高分函数
最高分函数时候按照总分的大小进行寻找,遍历完返回最高分所在的索引
注意事项:
参考代码:
#include<stdio.h>
#define MAX 10
struct Student{
char id[5];
char name[10];
int score[3];
};
void input(struct Student *stu){
getchar();
scanf("%s %s %d %d %d",stu->id,stu->name,&stu->score[0],&stu->score[1],&stu->score[2]);
}
void print(int n,struct Student stu[]){
int total_1 = 0;
int total_2 = 0;
int total_3 = 0;
//计算每一科的分数
for(int i=0;i<n;i++){
total_1 += stu[i].score[0];
total_2 += stu[i].score[1];
total_3 += stu[i].score[2];
}
printf("%d %d %d\n",total_1 /n,total_2/n,total_3/n);
}
int fing_Max(int n ,struct Student stu[]){
int flag = 0,max =0,total=0;
for(int i=0;i<n;i++){
for(int j=0;j<3;j++){
total = total + stu[i].score[j];
}
if(max < total){
flag = i;
max = total;
total = 0;
}
}
return flag;
}
void print_in(int flag,struct Student stu[]){
printf("%s %s %d %d %d",stu[flag].id,stu[flag].name,stu[flag].score[0],stu[flag].score[1],stu[flag].score[2]);
}
int main(){
struct Student student[MAX];
int n ;
int flag =0;
scanf("%d",&n);
for(int i=0;i<n;i++){
input(&student[i]);
}
print(n,student);
flag = fing_Max(n,student);
print_in(flag,student);
}
0.0分
2 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复