大神,求帮助。要求用一个input函数输入5个学生数据;但是每次输入到第三人时就会出错
#include<stdio.h>struct rec
{
int number;
char name[26];
float score[4];
};
void input(struct rec a[]);
float average(struct rec a[]);
int max(struct rec a[]);
#define N 5
int main()
{
struct rec student[N];
int i,m;
float ave;
input( student );
ave=average( student );
m=max( student );
printf("%.2f\n",ave);
printf("%d\n",student[m].number);
printf("%s\n",student[m].name);
for(i=0;i<3;i++)
printf("%.2f\n",student[m].score[i]);
printf("%.2f\n",student[m].score[3]);
return 0;
}
void input(struct rec a[])
{
int i,j;
for(i=0;i<N;i++)
{
scanf("%d",&a[i].number);
gets( a[i].name );
for(j=0;j<3;j++)
scanf("%f",&a[i].score[j]);
}
}
float average(struct rec a[])
{
int i,j;
float s=0,sum;
for(i=0;i<N;i++)
{
sum=0;
for(j=0;j<3;j++)
{
sum+=a[i].score[j];
s+=a[i].score[j];
}
a[i].score[3]=sum/3;
}
return s/(N*3);
}
int max(struct rec a[])
{
int i,j;
float max;
max=a[0].score[3];
for(i=0;i<N;i++)
{
if(max>a[i].score[3])
{
max=a[i].score[3];
j=i;
}
}
return j;
}
[ 本帖最后由 遇见sxm 于 2015-5-27 23:30 编辑 ]