Sum of diagonals
Submissions: 1546   Accuracy:

43.29%

  Difficulty: School   Marks: 0
*School Problem's Submission isn't counted in score!

Given a 2-D square matrix, find sum of elements in Principal and Secondary diagonals. For example, consider the following 4 X 4 input matrix.

A00 A01 A02 A03
A10 A11 A12 A13
A20 A21 A22 A23
A30 A31 A32 A33

The primary diagonal is formed by the elements A00, A11, A22, A33. And the secondary diagonal is formed by the elements A03, A12, A21, A30.

Input:
The first line consists of an integer T i.e number of test cases. The first line of each test case consists of an integer N.The next line consists of N*N spaced integers. 

Output:
Print the sum of primary diagonal elements and the secondary diagonal elements with a space in between.

Constraints: 
1<=T<=100
1<=N,a[i][j]<=1000

Example:
Input:

2
4
1 2 3 4 4 3 2 1 7 8 9 6 6 5 4 3
3
1 1 1 1 1 1 1 1 1 

Output:
16 20
3 3

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Ashtputre
Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.