//work out the sums of rows printf(“\n”); for(i=0;i<M;i++) { sum=0; for(j=0;j<N;j++) sum+=a[i][j]; printf(“Sum of Row %d is %d.\n”,i,sum); printf(“And the average is %f.\n”,1.0*sum/N); } printf(“\n”);
//work out the sums of columns for(j=0;j<N;j++) { sum=0; for(i=0;i<M;i++) sum+=a[i][j]; printf(“Sum of Column %d is %d.\n”,i,sum); printf(“And the average is %f.\n”,1.0*sum/M); } }
#include “stdio.h”
#define M 5
#define N 4
void main()
{
int a[M][N];
int i,j,sum;
//print the array
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
a[i][j]=i+j;
printf(“%4d”,a[i][j]);
}
printf(“\n”);
}
//work out the sums of rows
printf(“\n”);
for(i=0;i<M;i++)
{
sum=0;
for(j=0;j<N;j++)
sum+=a[i][j];
printf(“Sum of Row %d is %d.\n”,i,sum);
printf(“And the average is %f.\n”,1.0*sum/N);
}
printf(“\n”);
//work out the sums of columns
for(j=0;j<N;j++)
{
sum=0;
for(i=0;i<M;i++)
sum+=a[i][j];
printf(“Sum of Column %d is %d.\n”,i,sum);
printf(“And the average is %f.\n”,1.0*sum/M);
}
}
在这里面看的不是很清楚,你可以把它们复制到VC里面再看,那样应该会更清楚一点。
我也是菜鸟,我们共同学习吧,祝你成功。
太感谢了,呵呵,我要好好研究一下…