Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5701 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 938 |
@bt8816103042 | 739 |
@SHOAIBVIJAPURE | 428 |
@codeantik | 412 |
@SherlockHolmes3 | 407 |
@neverevergiveup | 348 |
@mahlawatep | 347 |
@shalinibhataniya1097 | 343 |
@murarry3625 | 333 |
@saiujwal13083 | 326 |
@rohitanand | 314 |
Complete Leaderboard |
Given a square of matrix M of size N*N. You task is to compute and return sum of principal diagonal elements of matrix. Your have to complete the function diagonalSum() which accepts N (size of matrix, N*N) and matrix M[ ][ ] as arguments.
Input:
The first input line contains T, denoting the number of testcases. Each testcase contains two lines. The first line contains N (size of matrix). The second line contains N*N elements of matrix separated by space.
Output:
For each testcase in new line, print the sum of diagonal elements.
User Task:
Since this is a functional problem you don't have to worry about input, you just have to complete the function sumDiagonal().
Constraints:
1 <= T <= 100
1 <= N <= 50
1 <= M[i][j] <= 100
Example:
Input:
1
3
1 2 3 4 5 6 7 8 9
Output:
15
Explanation:
Testcase 1: Sum of diagonal elements are: 1+5+9 = 15.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes