Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 308 Bytes

38.md

File metadata and controls

25 lines (22 loc) · 308 Bytes

题目:求一个3*3矩阵对角线元素之和。

#include<stdio.h>

int main()
{
	int a[3][3];
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			scanf("%d", &a[i][j]);
		}
	}

	int sum = 0;
	for (int i = 0; i < 3; ++i)
	{
		sum += a[i][i];
	}
	printf("%d", sum);

	return 0;
}