QUESTION DESCRIPTION
A symmetric matrix is a square matrix that is equal to its transpose.
TEST CASE 1
Not Symmetric
TEST CASE 2
Symmetric
SOLUTION : (Please use this as reference only)
A symmetric matrix is a square matrix that is equal to its transpose.
Write a C program to find whether a given matrix is a square matrix or not.
Input Format:
The input consists of (m*n+2) integers. The first integer corresponds to m, the number of rows in the matrix and the second integer corresponds to n, the number of columns in the matrix. The remaining integers correspond to the elements in the matrix. The elements are read in rowwise order, first row first, then second row and so on. Assume that the maximum value of m and n is 10
Input Format:
The input consists of (m*n+2) integers. The first integer corresponds to m, the number of rows in the matrix and the second integer corresponds to n, the number of columns in the matrix. The remaining integers correspond to the elements in the matrix. The elements are read in rowwise order, first row first, then second row and so on. Assume that the maximum value of m and n is 10
TEST CASE 1
INPUT
3 3
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9
OUTPUT
Not Symmetric
TEST CASE 2
INPUT
3 3
3 1 1
1 3 1
1 1 5
3 1 1
1 3 1
1 1 5
OUTPUT
Symmetric
EXPLANATION :
The code requires you to check whether a given square matrix is a symmetric matrix or not ( Symmetric Matrix )
ALGORITHM :
- Accept the number of rows and columns from user ( n,m )
- Check if array is a square matrix ( n==m )
- Accept the elements of the array using scanf ( arr[][] )
- Check if array elements are symmetric ( arr[i][j]==arr[j][i] )
- If the condition fails , change flag to 0 and jump out of the 2 loops ( goto here )
- If the array is not a square change flag to 0
- After the loop check if flag is 0 or 1 ( flag==1 )
- Print the appropriate result for the two cases
SOLUTION : (Please use this as reference only)
CODE |
No comments:
Post a Comment