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

Programming Exercises

Calculate the sum of the diagonal elements in a 3x3 matrix.

Medium

Problem Statement

Calculate the sum of the diagonal elements in a 3x3 matrix.

Sample Input

Matrix:
 1 2 3
 4 5 6
 7 8 9

Sample Output

Sum of diagonal elements: 15

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <stdio.h> int diagonalSum(int matrix[3][3]) { // Your code here } int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("Sum of diagonal elements: %d\n", diagonalSum(matrix)); return 0; }
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
Sum of diagonal elements: 15