Problem Description
求一个3×3的整型矩阵对角线元素之和。
Input Description
从键盘上输入3×3的整型矩阵,要求输入3行,每行3个整数,每个数之间以空格分隔
Output Description
对角线元素之和,行尾换行。
Sample Input
1 2 3
4 5 6
9 8 7
Sample Output
13
#include<stdio.h>
int main()
{int a[3][3];
int i=0;
int b=0;
while(i<3){
int n=0;
while(n<3){
scanf("%d",&a[i][n]);
n++;
}
i++;
}
i=0;
while(i<3){
b=b+a[i][i];
i++;
}
printf("%d",b);
return 0;
}