Lab
Lab
Write a program to declare a square matrix A[][] of order M × M where ‘M’ is the number of
rows and the number of columns, such that M must be greater than 2 and less than 10.
Accept the value of M as user input. Display an appropriate message for an invalid input. Allow
the user to input integers into this matrix. Perform the following tasks:
(a) Display the original matrix.
(b) Check if the given matrix is said to be symmetric or not. A square matrix is said to be
symmetric, if the element of the ith row and jth column is equal to the element of the jth row and
ith column.
(c) Find the sum of the elements of left diagonal and the sum of the elements of right diagonal
of the matrix and display them.
Example 1
INPUT:
M=3
Enter elements of the matrix:
123
245
356
OUTPUT:
ORIGINAL MATRIX
123
245
356
THE GIVEN MATRIX IS SYMMETRIC.
THE SUM OF THE LEFT DIAGONAL = 11
THE SUM OF THE RIGHT DIAGONAL = 10
Example 2
INPUT:
M=4
Enter elements of the matrix:
7892
4563
8531
7642
OUTPUT:
ORIGINAL MATRIX
7892
4563
8531
7642
THE GIVEN MATRIX IS NOT SYMMETRIC.
THE SUM OF THE LEFT DIAGONAL = 17
THE SUM OF THE RIGHT DIAGONAL = 20
Example 3
INPUT: M = 12
OUTPUT: SIZE IS OUT OF RANGE.