① 代码:
#include
int main(int argc, char const 铅源*argv[])
{
int a[3][3], i, j, sum_diag_l, sum_diag_r;
sum_diag_l = sum_diag_r = 0;
for (i = 0; i < 3; ++i)
for (j = 0; j < 3; ++j)
scanf("%d", 知激指&a[i][j]);
for (i = 0; i < 3; ++i) {
sum_diag_l += a[i][i];
sum_diag_r += a[i][2-i];
}
printf("The sum of primary diagonal = %d\n", sum_diag_l);
printf("The sum of secondary diagonal = %d\n", sum_diag_r);
return 0;
}
② 运行:
1 3 6 4 2 5 9 8 7
The 搭配sum of primary diagonal = 10
The sum of secondary diagonal = 17