WRITE A C-PROGRAM TO TEST THE GIVEN MATRIX IS SYMMETRIC (OR) NOT.
AIM:A program to test the given matrix is symmetric (or) not
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],b[10][10],i,j,m,n;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
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++)
b[i][j]=a[j][i];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]==b[i][j])
printf("it is a symmetric matrix");
else
printf("it is not a symmetric matrix");
}
OUTPUT:
enter the values of m,n
2,2
enter the elements of matrix a
1 3 2 5
it is a symmetric matrix
This comment has been removed by the author.
ReplyDeleteit wrong program
ReplyDelete#include
ReplyDelete#include
main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix\n");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
scanf("%d",&matrix[c][d]);
for( c = 0 ; c < m ; c++ )
{
for( d = 0 ; d < n ; d++ )
{
transpose[d][c] = matrix[c][d];
}
}
if ( m == n ) /* check if order is same */
{
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < m ; d++ )
{
if ( matrix[c][d] != transpose[c][d] )
break;
}
if ( d != m )
break;
}
if ( c == m )
printf("Symmetric matrix.\n");
}
else
printf("Not a symmetric matrix.\n");
return 0;
}