DevJourney · code I wrote while learning

Sum of Diagonals of 3D Matrix

2 items

README.md

Single File Programming Question

Problem Statement

Meet Professor Henry, a brilliant mathematician who loves solving brain teasers. One day, he stumbles upon an intriguing problem - finding the sum of the diagonals in a 3D matrix. He decides to write a program to solve it using pointers and multi-dimensional concepts but realizes that the task is more challenging than he thought.

Therefore, assist him in writing a program that calculates the sum of the diagonals in a 3D matrix.

Input format :

The first line of the input consists of three space-separated integers: rows, columns, and height representing the dimensions of the 3D matrix.

The next lines of the input consist of integers representing the elements of the 3D matrix.

Output format :

The output displays a single integer representing the sum of the main diagonal elements in the 3D matrix if the matrix is a cubic matrix.

Otherwise, the output displays a message as "Error" and terminates.

Refer to the sample output for the formatting specifications.

Code constraints :

1 ≤ rows, columns, height ≤ 5

1 ≤ Elements in the matrix ≤ 1000

Sample test cases :

Input 1 :

3 3 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Output 1 :

42

Input 2 :

2 3 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Output 2 :

Error Whitelist Set 1: *