输入2个正整数 m 和 n (1<=m<=6, 1<=n<=6),然后输入该m行n列矩阵a中的元素

2024-11-23 07:17:52
推荐回答(2个)
回答(1):

#include
int main()
{
int sum,i,j,n,m;
scanf("%d%d",&m,&n);
int a[6][6];
for(i=0;i {
for(j=0;j { scanf("%d",&a[i][j]);
}
}
for(i=0;i {
sum = 0; // 每次将sum初始化为 0,即可
for(j=0;j {
sum=a[i][j]+a[i][j+1];
printf("sum of row %d is %d\n",i,sum);
}
}
return 0 ;
}

忘了将sum初始化为 0

回答(2):

for(i=0;i for(j=0;j sum=a[i][j]+a[i][j+1];
printf("sum of row %d is %d\n",i,sum);
改成

for(i=0;isum=0;
for(j=0;j<=n-1;j++){
sum+=a[i][j];
printf("sum of row %d is %d\n",i,sum);}试试看