Previous Next
0 / 15
Module DEMO-33-66DEMO-OOP-33

Matrix Diagonal Sum

DEMO-OOP-33 โ€ข Object Oriented Programming

Browser-only practice

Problem Statement

Read a 3x3 matrix and print the sum of the main diagonal.

Input Format

Input is given as whitespace-separated tokens in this order:

  1. row 1 col 1
  2. row 1 col 2
  3. row 1 col 3
  4. row 2 col 1
  5. row 2 col 2
  6. row 2 col 3
  7. row 3 col 1
  8. row 3 col 2
  9. row 3 col 3

Output Format

Print the exact report in this order:

  1. Diagonal Sum

Sample Testcases

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

Sample #1
Public sample
1
2
3
4
5
6
7
8
9
Diagonal Sum: 15
Input: row 1 col 1 = 1, row 1 col 2 = 2, row 1 col 3 = 3, row 2 col 1 = 4, row 2 col 2 = 5, row 2 col 3 = 6, row 3 col 1 = 7, row 3 col 2 = 8, row 3 col 3 = 9.
Key calculation(s): matrix = { | {1, 2, 3}, | "Diagonal Sum: " + diagonal = "Diagonal Sum: 15".
Output:
Diagonal Sum: 15
Sample #2
Public sample
9
8
7
6
5
4
3
2
1
Diagonal Sum: 15
Input: row 1 col 1 = 9, row 1 col 2 = 8, row 1 col 3 = 7, row 2 col 1 = 6, row 2 col 2 = 5, row 2 col 3 = 4, row 3 col 1 = 3, row 3 col 2 = 2, row 3 col 3 = 1.
Key calculation(s): matrix = { | {9, 8, 7}, | "Diagonal Sum: " + diagonal = "Diagonal Sum: 15".
Output:
Diagonal Sum: 15

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