输入10个学生5门课的成绩,分别用函数实现下列功能:
1、计算每个学生平均分
2、计算每门课程的平均分
3、找出所有50个分数中最高的分数所对应的学生和课程
4、计算平均分方差:
其中,xi为某一学生的平均分。
【c源程序】
#include
#define N 10
#define M 5
float score[N][M];
float a_stu[N],a_cour[M];
int r,c;
int main()
{ int i,j;
float h;
float s_var(void);
float highest();
void input_stu(void);
void aver_stu(void);
void aver_cour(void);
input_stu();
aver_stu();
aver_cour();
printf("\n NO. cour1 cour2 cour3 cour4 cour5 aver\n");
for(i=0;i
{printf("\n NO %2d ",i+1);
for(j=0;j
printf("%8.2f",score[i][j]);
printf("%8.2f\n",a_stu[i]);
}
printf("\naverage:");
for (j=0;j
printf("%8.2f",a_cour[j]);
printf("\n");
h=highest();
printf("highest:%7.2f NO. %2d course %2d\n",h,r,c);
printf("variance %8.2f\n",s_var());
return 0;
}
void input_stu(void)
{int i,j;
for (i=0;i
{printf("\ninput score of student%2d:\n",i+1);
for (j=0;j
scanf("%f",&score[i][j]);
}
}
void aver_stu(void)
{int i,j;
float s;
for (i=0;i
{for (j=0,s=0;j
s+=score[i][j];
a_stu[i]=s/5.0;
}
}
void aver_cour(void)
{int i,j;
float s;
for (j=0;j
{s=0;
for (i=0;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
for (j=0;j
if (score[i][j]>high)
{high=score[i][j];
r=i+1;
c=j+1;
}
return(high);
}
float s_var(void)
{int i;
float sumx,sumxn;
sumx=0.0;
sumxn=0.0;
for (i=0;i
{sumx+=a_stu[i]*a_stu[i];
sumxn+=a_stu[i];
}
return(sumx/N-(sumxn/N)*(sumxn/N));
}