解题思路:写三个子函数,分别赋值,求平均,求最大
注意事项:
参考代码:
#include"stdio.h"
int n;
struct
{
char num[20];
char name[20];
unsigned int score[3];
}chengji[100];
void fuzhi()
{
unsigned int i;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
scanf("%s %s %d %d %d",
&chengji[i].num,
&chengji[i].name,
&chengji[i].score[0],
&chengji[i].score[1],
&chengji[i].score[2]);
}
}
void print_average()
{
unsigned int a1=0,a2=0,a3=0;
unsigned int i;
for(i=0;i<n;i++)
{
a1 += chengji[i].score[0];
a2 += chengji[i].score[1];
a3 += chengji[i].score[2];
}
a1 /= n;
a2 /= n;
a3 /= n;
printf("%d %d %d\n",a1,a2,a3);
}
void print_max()
{
unsigned int aver[10];
unsigned int i;
unsigned int j;
unsigned int temp;
unsigned int flag;
for(i=0;i<n;i++)
{
aver[i] = chengji[i].score[0] + chengji[i].score[1] +chengji[i].score[2];
}
temp = aver[0];
for(j=1;j<n;j++)
{
if(temp<aver[j])
{
temp = aver[j];
flag = j;
}
else
{
flag = 0;
}
}
printf("%s %s %d %d %d",chengji[flag].num,chengji[flag].name,chengji[flag].score[0],chengji[flag].score[1],chengji[flag].score[2]);
}
int main()
{
fuzhi();
print_average();
print_max();
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:1158 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:687 |
简单的a+b (C语言代码)浏览:641 |
C语言程序设计教程(第三版)课后习题6.3 (C++代码)浏览:1067 |
1014题解浏览:524 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:594 |
A+B for Input-Output Practice (I) (C语言代码)浏览:451 |
1162答案错误,为什么浏览:700 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:559 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:441 |