参考代码:
#include<stdio.h>
typedef struct stu {
char num[100];
char name[100];
int score[3];
};
void input(struct stu* p, int n) {
for(int i = 0; i < n; i++) {
scanf("%s%s%d%d%d", &(p[i].num), &(p[i].name), &(p[i].score[0]), &(p[i].score[1]), &(p[i].score[2]));
}
}
void output(struct stu* p, int n) {
double a=0, b=0, c=0,avg1, avg2, avg3;
for (int i = 0; i < n; i++) {
a+= p[i].score[0];
b+= p[i].score[1];
c+= p[i].score[2];
}
avg1 = a / n;
avg2 = b / n;
avg3 = c / n;
printf("%.0lf %.0lf %.0lf\n", avg1, avg2, avg3);
int i,max=0;
for(i=0;i<n;i++){
if(max<=(p[i].score[0]+p[i].score[1]+p[i].score[2])){
max=p[i].score[0]+p[i].score[1]+p[i].score[2];
}
}
for(i=0;i<n;i++){
if((p[i].score[0]+p[i].score[1]+p[i].score[2])==max){
printf("%s %s %d %d %d\n", p[i].num, p[i].name, p[i].score[0], p[i].score[1], p[i].score[2]);
}
}
}
int main()
{
int n;
scanf("%d", &n);
struct stu a[n];
input(a, n);
output(a, n);
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:564 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:573 |
printf基础练习2 (C语言代码)浏览:690 |
三角形 (C++代码)递推浏览:825 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:760 |
哥德巴赫曾猜测 (C语言代码)浏览:2560 |
1118(求助_已解决)浏览:351 |
盐水的故事 (C语言代码)浏览:1602 |
简单的a+b (C语言代码)浏览:531 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:660 |