Diagonal sum
Submissions: 2959   Accuracy:

31.42%

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

Given a square matrix of size M×M. Your task is to calculate the sum of its diagonals.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. First line of each test case contains a single integer M denoting the size of the square matrix. The next  line contains M*M space separated values of the matrix A.

Output:
For each test case in a new line print the sum of diagonals of the matrix.

Constraints:
1  ≤  T  ≤  20
2  ≤  M  ≤  10
1  ≤  A[i]  ≤  20

Example:
Input:
1
3
1 1 1 1 1 1 1 1 1

Output:
6

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

Contributor: karan kumar
Author: karanshrm44


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.