- Write a C program to check whether a matrix is symmetric matrix or not.

#### Required Knowledge

This program checks whether a given matrix is symmetric matrix or not. Here is the algorithm to check symmetric matrix.

**Algorithm to find symmetric matrix**

*Let inputMatrix is an integer matrix having N rows and M columns.*

- Find transpose matrix of inputMatrix and store it in transposeMatrix. Check this C program to find transpose of a matrix.
- Compare inputMatrix and transposeMatric. Check this C program to compare two matrix
- If both matrices are equal then inputMatrix is symmetric matrix otherwise not a symmetric matrix

## C program to check a matrix is symmetric matrix or not

#include <stdio.h> #include <conio.h> int main(){ int rows, cols, row, col, size, isSymmetric; int inputMatrix[50][50], transposeMatrix[50][50]; printf("Enter the size of Square Matrix\n"); scanf("%d", &size); rows = cols = size; printf("Enter Matrix of size %dX%d\n", rows, cols); for(row = 0; row < rows; row++){ for(col = 0; col < cols; col++){ scanf("%d", &inputMatrix[row][col]); } } /* Find Transpose of inputMatrix transpose[i][j] = inputMatrix[j][i] */ for(row = 0; row < rows; row++){ for(col = 0; col < cols; col++){ transposeMatrix[col][row] = inputMatrix[row][col]; } } /* Compare Input Matrix and its Transpose Matrix */ isSymmetric = 1; for(row = 0; row < cols; row++){ for(col = 0; col < rows; col++){ if(inputMatrix[row][col] != transposeMatrix[row][col]){ isSymmetric = 0; } } } if(isSymmetric == 1) printf("Input Matrix is Symmetric Matrix\n"); else printf("Input Matrix is Not a Symmetric Matrix\n"); getch(); return 0; }Output

Enter the size of Square Matrix 3 Enter Matrix of size 3X3 4 5 6 5 9 1 6 1 2 Input Matrix is Symmetric Matrix

Enter the size of Square Matrix 3 Enter Matrix of size 3X3 1 2 3 4 5 6 7 8 9 Input Matrix is Not a Symmetric Matrix

**Related Topics**