This is sample program in C++ to check if a given matrix is symmetric or not. In a symmetric matrix if the rows are transposed to columns, the transposed matrix is same as the first one.
Example:
1 2 3
2 4 5
3 5 6
is a symmetric matrix.
Here is the code:
#include<iostream> using namespace std; int main() { int a[25][25],i,j,flag=0, rows, cols; cout << "How many rows and columns the matrix has: "; cin >> rows >> cols; if (rows != cols) cout << "The matrix cannot be checked for symmetry: " << endl; else { cout << "Enter the elements of the matrix: " << endl; for (i=0;i> a[i][j]; } } } for (i=0;i<3;i++) { for(j=0;j<1;j++) { if(a[i][j] != a[j][i]) flag=1; } } if (flag) cout << "The matrix is not symmetric)" << endl; else cout << "The matrix is symmetric" << endl; return 0; }