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

Lab Exercise

27. Write a program to evaluate the addition of diagonal elements of two square matrixes.

Sample Input and Output

Stdin Inputs:

3 5 6 7 41 65 8 45 7 4 3 14 78 45 78 57 43 19 46 35

Sample Result:

Input no of rows or columns of first matrix: 3

***Input first matrix***
Input element 1, 1: 5
Input element 1, 2: 6
Input element 1, 3: 7
Input element 2, 1: 41
Input element 2, 2: 65
Input element 2, 3: 8
Input element 3, 1: 45
Input element 3, 2: 7
Input element 3, 3: 4

Input no of rows or columns of second matrix: 3

***Input second matrix***
Input element 1, 1: 14
Input element 1, 2: 78
Input element 1, 3: 45
Input element 2, 1: 78
Input element 2, 2: 57
Input element 2, 3: 43
Input element 3, 1: 19
Input element 3, 2: 46
Input element 3, 3: 35

***First Matrix***
5     6     7
41     65     8
45     7     4

***Second Matrix***
14     78     45
78     57     43
19     46     35

Sum of diagonal elements of first matrix (Sum 1): 74
Sum of diagonal elements of second matrix (Sum 2): 106
Sum 1 < Sum 2

Leave a Reply

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

Scroll to Top
Scroll to Top