بيان المشكلة
Write a program to calculate the sum of the main diagonal elements (where row index equals column index) of a square matrix.
DEMO-C-32 • Programming in C
Write a program to calculate the sum of the main diagonal elements (where row index equals column index) of a square matrix.
Input: Dimensions N M followed by the matrix elements.
Output: The formatted result as specified.
Submit runs every public testcase in this browser. Results and code never leave this device.
4 4 41 48 1 10 47 5 34 32 19 11 38 -1 15 17 46 4
88
5 5 33 12 41 22 19 7 48 12 1 50 30 -10 16 0 14 28 49 18 4 25 -1 -2 41 44 7
108
4 4 46 9 28 6 -10 13 44 16 45 38 20 42 16 50 4 -9
70
2 2 -10 48 23 4
-6
C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.
/workspace/question