求高手帮忙!
我做的是求10个学生的5门课程的平均分!
我觉得我编的没错为什么我的输出只有一个课程的成绩的?
帮个忙吧!
谢谢了!
程序如下:
#define N 10
#define M 5
float score[N][M];
float a_stu[N],a_cour[M];
int r,c;
main()
{float s_var(void);
float highest();
void input_stu(void);
void aver_stu(void);
void aver_cour(void);
int i,j;
float h;
input_stu();
aver_stu();
aver_cour();
printf("\n NO. cour1 cour2 cour3 cour4 cour5 aver");
for(i=0;i<N;i++)
{printf("\n NO.%2d",i+1);
for(j=0;j<M;j++);
printf("%8.2f",score[i][j]);
printf("%8.2f",a_stu[i]);
}
printf("\naverage:");
for(j=0;j<M;j++)
printf("%8.2f",a_cour[j]);
h=highest();
printf("\nhighest:%7.2f NO.%2d course%2d\n",h,r,c);
}
void input_stu(void)
{int i,j;
for (i=0;i<N;i++)
{printf("\nInput score of student%2d:\n",i+1);
for(j=0;j<M;j++)
scanf("%f",&score[i][j]);
}
}
void aver_stu(void)
{int i,j;
float s;
for (i=0;i<N;i++)
{for (j=0,s=0;j<M;j++)
s+=score[i][j];
a_stu[i]=s/5.0;
}
}
void aver_cour(void)
{int i,j;
float s;
for(j=0;j<M;j++)
{s=0;
for(i=0;i<N;i++)
s+=score[i][j];
a_cour[j]=s/(float)N;
}
}
float highest()
{float high;
int i,j;
high=score[0][0];
for(i=0;i<N;i++)
for(j=0;j<M;j++)
if(score[i][j]>high)
{high=score[i][j];
r=i+1;
c=j+1;
}
return(high);
}
[此贴子已经被作者于2005-12-7 20:31:13编辑过]