Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a program to find the sum of diagonal elements in a hardcoded 2D square matrix.

Medium

Problem Statement

Create a program to find the sum of diagonal elements in a hardcoded 2D square matrix.

Sample Input

Matrix:
[ [1, 2, 3],
 [4, 5, 6],
 [7, 8, 9] ]

Sample Output

Diagonal Sum: 15

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
using System; class DiagonalSum { static void Main() { // Find the sum of diagonal elements in the matrix } }
Log in or sign up to run or submit your code.Log inSign up
Input
Matrix:
[ [1, 2, 3],
 [4, 5, 6],
 [7, 8, 9] ]
Expected Output
Diagonal Sum: 15