Skip to main content

Posts

Showing posts with the label Total Sum on the Boundaries and Diagonals

Total Sum on the Boundaries and Diagonals

  Total Sum on the Boundaries and Diagonals Send Feedback For a given two-dimensional square matrix of size (N x N). Find the total sum of elements on both the diagonals and at all the four boundaries. Input format: The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow. First line of each test case or query contains a single integer value, 'N' representing the 'rows' and 'columns' for the two-dimensional square matrix. Second line onwards, the next 'N' lines or rows represent the ith row values. Each of the ith row constitutes 'N' column values separated by a single space. Output format: For each test case, print the single integer denoting the sum. Output for every test case will be printed in a seperate line. Constraints: 1 <= t <= 10^2 0 <= N <= 10^3 Time Limit: 1sec Sample input 1: 1 3 1 2 3 4 5 6 7 8 9 Sample Output 1: 45 Explanation for Sample O...