printf("%4d", s[i][j]);应改为printf("%4d", s1[i][j]);
for (i = 0; i < n; i++)
{
sum1 += s1[i][i];
for (j = 0; j < n; j++)
{
sum2 += s1[i][j];
if (i == 0 || j == 0 || i == n - 1 || j == n - 1)
{
sum3 += s1[i][j];
}
}
}
sum = sum2 - sum3;
printf("sum1=%d\n", sum1);
printf("sum=%d", sum);
return 0;
}
改为:
for (i = 0; i < n; i++){
sum2 += s1[i][i];//sum1 += s1[i][i];
for (j = 0; j < n; j++){
sum += s1[i][j];//sum2 += s1[i][j];
if (i == 0 || j == 0 || i == n - 1 || j == n - 1){
sum3 += s1[i][j];
}
}
}
sum1 = sum - sum3;
printf("sum1=%d\n", sum1);
printf("sum2=%d\n", sum2);
且定义sum时要初始化为0
哪里出错了?我感觉完全正确啊