#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
}
}
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
for(i=0;i
printf("sum of row %d is %d\n",i,sum);
改成
for(i=0;i
for(j=0;j<=n-1;j++){
sum+=a[i][j];
printf("sum of row %d is %d\n",i,sum);}试试看