Dr. A.P.J. Abdul Kalam Technical University (AKTU), Lucknow

Lab Exercise

27. Write a program to find the sum of diagonal elements of a m x n matrix.

Sample Input and Output

Stdin Inputs:

3 4 5 9 7 11 4 8 6 10 3 1 2 12

Sample Result:

***Input matrix***
Input number of rows: 3
Input number of columns: 4
Input element 1 1: 5
Input element 1 2: 9
Input element 1 3: 7
Input element 1 4: 11
Input element 2 1: 4
Input element 2 2: 8
Input element 2 3: 6
Input element 2 4: 10
Input element 3 1: 3
Input element 3 2: 1
Input element 3 3: 2
Input element 3 4: 12

***Matrix***
5     9     7     11
4     8     6     10
3     1     2     12

Sum of Diagonal elements: 15

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top