0
2.6kviews
Define a function to check whether enter square matrix is symmetric or not. Pass square matrix as an argument from main program to function.
1 Answer
0
46views
#include<stdio.h>
#include<conio.h>
void trans_sym (int trans[][];int a; int b)
{
    int i,j, transpose [10][10];
for( i = 0 ; i < a ; i++ )
   {
      for( j = 0 ; j < b ; j++ )
      {
         transpose[i][j] = trans[j][i];
      }
   }
   if ( m == n ) /* check if order is same */
   {
       for ( i = 0 ; i < a ; i++ )
       {
           for ( j = 0 ; j < b ; j++ )
           {
               if ( trans[i][j] != transpose[i][j] )
break;
           }
           if ( j != b )
break;
       }
       if ( i == a )
          printf("Symmetric matrix.\n");
   }
   else
       printf("Not a symmetric matrix.\n");

   return 0;
}
void main()
{
   int m, n, c, d, matrix[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]);
    trans_sym (matrix,m,n);
getche();
}

Output

Enter the number of rows and columns of matrix

2

2

Enter the elements of matrix

1

2

3

4

Not a symmetric matrix

Please log in to add an answer.