0
3.2kviews
Write a program in C to read and display elements of a square (2D) matrix and check whether the entered matrix is symmetric or not.
1 Answer
written 8.3 years ago by |
Program:
#include<stdio.h>
#include<conio.h>
int main() {
int a[10][10], i, j, m, n, r=1;
printf("Enter the order of matrix:");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix\n");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d",&a[i][j]);
for( i = 0 ; i < m ; i++ )
{
for( j = 0 ; j < n ; j++ )
if(a[i][j]!=a[j][i])
{
r=0;
}
}
}
if(r==1)
{
printf("Symmetric Matrix\n");
}
else
{
printf("Not a Symmetric Matrix.\n");
}
} //main ends
Output: Enter the order of matrix: 3 3 Enter the elements of matrix:
1 2 4
2 4 6
4 6 5
Symmetric Matrix