C语言编程用二维数组定义5个学生4门成绩,有独立的输入输出函数,求每
C语言编程用二维数组定义5个学生4门成绩,有独立的输入输出函数,求每个学生的平均分放在最右列,每科成绩的平均分放在最下行...
C语言编程用二维数组定义5个学生4门成绩,有独立的输入输出函数,求每个学生的平均分放在最右列,每科成绩的平均分放在最下行
展开
1个回答
2016-11-18
展开全部
#include <stdio.h>
#include <stdlib.h>
void getscore(float s[6][5])
{
int i,j;
float t;
for(i=0;i<5;i++)
for(j=0;j<4;j++)
{ scanf("%f",&t); s[i][j]=t;}
}
void printscore(float s[6][5])
{
int i,j;
for(i=0;i<6;i++){
for(j=0;j<5;j++)
printf("%5.2g",s[i][j]);
printf("\n");
}
}
void aver(float a[6][5])
{
int i,j;
float s,cs[4];
for(j=0;j<4;j++) cs[j]=0;
for(i=0;i<5;i++){
s=0;
for(j=0;j<4;j++){
s += a[i][j];
cs[j] += a[i][j]/5;
}
a[i][4]=s/4;
}
s=0;
for(j=0;j<4;j++){ a[5][j]=cs[j]; s+=cs[j]; }
a[5][4] = s/4;
}
int main()
{
float score[6][5];
getscore(score);
aver(score);
printscore(score);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询