解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu{
char num[20];
char name[10];
int score1;
int score2;
int score3;
};
int input(struct stu *p,int N)
{
struct stu *q;
for(q=p;q<p+N;q++)
{
scanf("%s%s%d%d%d",&(q->num),&(q->name),&(q->score1),&(q->score2),&(q->score3));
}
return 0;
}
int average(struct stu *p,int N)
{
int i,tmp1=0,tmp2=0,tmp3=0;
for(i=0;i<N;i++)
{
tmp1+=(p+i)->score1;
}
for(i=0;i<N;i++)
{
tmp2+=(p+i)->score2;
}
for(i=0;i<N;i++)
{
tmp3+=(p+i)->score3;
}
printf("%d %d %d\n",tmp1/N,tmp2/N,tmp3/N);
return 0;
}
int average2(struct stu *p,int N)
{
int i,k=0;
int a[N];
for(i=0;i<N;i++)
{
a[i]=((p+i)->score1+(p+i)->score2+(p+i)->score3)/3;
}
for(i=1;i<=N-1;i++)
{
if(a[0]<a[i])
{
k=i;
a[0]=a[k];
}
}
printf("%s %s %d %d %d\n",(p+k)->num,(p+k)->name,(p+k)->score1,(p+k)->score2,(p+k)->score3);
return 0;
}
int main()
{
int N;
scanf("%d",&N);
struct stu cl[N];
struct stu *p;
p=cl;
input(p,N);
average(p,N);
average2(p,N);
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1195 |
【蟠桃记】 (C语言代码)浏览:664 |
【魔板】 (C++代码)(时间超限,希望会的帮我改正一下)浏览:741 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:527 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:614 |
完数 (C语言代码)浏览:693 |
sizeof的大作用 (C语言代码)浏览:1450 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:548 |
数列有序 (C语言代码)浏览:935 |
筛排处理 (C语言代码)浏览:786 |