WRITE A PROGRAM TO CHECK WHETHER A MATRIX IS SYMMETRIC OR NOT:
#include<stdio.h>#include<conio.h>
void main()
{
int m,n,i,j,a[10][10],b[10][10],x=0;
clrscr();
printf("Enter the number of row:");
scanf("%d",&m);
printf("Enter the number of column:");
scanf("%d",&n);
printf("Enter the matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[j][i]=a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=b[i][j])
{
x++;
}
}
}
printf("The matrix is=> ");
x==0?printf("symmetric"):printf("not symmetric");
getch();
}
OUTPUT:
Enter the number of row: 2
Enter the number of column: 2
Enter the matrix:
4
4
4
4
The matrix is=>symmetric
To find whether a matrix symmetric or not we can use the following code:
ReplyDeletefor(i=0;i<n;i++)
for(j=0;j<n;j++)
if(a[i][j]!=a[j][i])
{ch='n';}
Visit this link for an in-depth explanation:
http://www.fixoncloud.com/Home/LoginValidate/OneProblemComplete_Detailed.php?problemid=328
For(i=0;i<m;i++)
ReplyDeletej=(i+1)%i;
if(a[i][j]!=a[j][i]) {
break;
}
if(i==m) {
printf("symmetric"):
}
else
printf("not symmetric");