Write a program to find the transpose of a given matrix & check whether it is symmetric or not

what is symmetric matrix:-   A matrix is said to be symmetric if matrix and it’s transpose is                                                  equal  . 

 Code:-

#include<stdio.h>
int main()
{
int a[10][10],t[10][10],i,j,flag=0;
int r,c;
printf(“Enter the number of row and column of the matrixn”);
scanf(“%d%d”,&r,&c);
printf(“Enter the element of the matrixn”);
// Input matrix a[][]
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf(“%d”,&a[i][j]);
}
// logic for compute transpose
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
{
t[i][j]=a[j][i];
}
}
// Display the transpose
printf(“the transpose is:-n”);
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
printf(“%d “,t[i][j]);
printf(“n”);
}
//logic for checking matrix is symmetric or not
if(r!=c)
printf(“Matrix is not symmetricn”);
else
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(t[i][j]!=a[i][j]);
{
flag=1;
break;
}
}
if(flag==1)
break;
}
if(flag==0)
printf(“Matrix is symmetric Matrixn”);
else
printf(“Matrix is not a symmetric Matrixn”);
}
return 0;
}

Output:-

Enter the number of row and column of the matrix
2 3
Enter the element of the matrix
2 1 3
2 4 8
the transpose of the matrix is:-
2 2
1 4
3 8
Matrix is not symmetric



Leave a Reply

Your email address will not be published.