Previous Next
0 / 21
Module DEMO-32-109DEMO-C-32

Anti-Diagonal Sum

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a program to calculate the sum of the anti-diagonal elements (from top-right to bottom-left) of a square matrix.

Constraints

1 <= N, M <= 10. Integers within standard range.

Input Format

Input: Dimensions N M followed by the matrix elements.

Output Format

Output: The formatted result as specified.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
4 4
16 26 31 44
7 11 1 42
50 -8 49 17
-6 -6 -2 50
31
Anti-diagonal sum = 31.
Sample #2
Public sample
4 4
-4 24 5 26
24 38 20 47
-3 36 -2 2
14 -9 18 1
96
Anti-diagonal sum = 96.
Sample #3
Public sample
4 4
-3 47 37 6
-3 -3 50 28
-4 24 4 38
39 1 16 -5
119
Anti-diagonal sum = 119.
Sample #4
Public sample
5 5
49 27 1 11 15
20 17 36 18 30
30 -4 -10 -9 7
44 -10 30 14 25
38 47 2 27 26
51
Anti-diagonal sum = 51.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings