Search across blog, articles, projects, courses, and community posts
For a square grid of numbers, the main diagonal runs from the top-left to the bottom-right and the anti-diagonal from the top-right to the bottom-left. Print the sum of each.
Input:
n, the size of the grid.n lines of n integers each.Output: main anti, separated by a space. If n is odd, the centre cell belongs to both diagonals.
1 <= n <= 100, values between -1000 and 1000.
3 1 2 3 4 5 6 7 8 9
15 15
2 1 2 3 5
6 5