【正确答案】程序源代码如下。
#define NUM std 5 /*定义符号常量人数为5*/
#define NUM couFse 4 /*定义符号常量课程为4*/
#include"stdio.h"
main()
{
int i,j;
static float score[NUM_std+1][NUM_course+1]={{78,85,83,65}, {88,91,89,93},{72,65,54,75}, {86,88,75,60}, {69,60,50,72}};
/*以上定义一个(NUM_std+1)*(NUM_course+1)的2维数组,并初始化,留下最后一列score[i][NUM_course]存放个人平均成绩,最后一行score[NUM_std][i]存放学科平均成绩*/
for(i=0;i<NUM_std;i++)
{
for(j=0;j<NUM_course;j++)
{
score[i][NUM_course]+=score[i][j];/*求第i个人的总成绩*/
score[NUM_std][j]+=score[i][j]; /*求第j门课的总成绩*/
}
score[i][NUM_course]/=NUM_course;/*求第i个人的平均成绩*/
}
for(j=0; j<NUM_course;j++)
score[NUM_std][j]/=NUM_std; /*求第j门课的平均成绩*/
clrscr():
/*输出表头*/
printf("学生编号课程1 课程2 课程3课程4 个人平均\n");
/*输出每个学生的各科成绩和平均成绩*/
for(i=0;i<NUM_std;i++)
{
printf("学生/%d\t",i+1);
for(j=0;j<NUM_course+1;j++)
printf("/%6.1f/t,score[i][j]);
printf("\n");
}
/*输出1条短划线*/
for(j=0;j<8*(NUM_course+2);j++)
printf("-");
printf("\n课程平均");
/*输出每门课程的平均成绩*/
for(j=0;j<NUM_course;j++)
printf("/%6.1f\t",score[NUM_std][j]);
printf("\n");
getch();
}
【答案解析】