‘C’ program to check if a n X n matrix is symmetric.

C File =>



/* Write a ‘C’ program to check if a nXn matrix is symmetric. */

#include<stdio.h>
int main() 
{
     int mat[30][30],i,j,m,n,flag=1;
     
     printf("\n Enter how many rows?");
     scanf("%d",&m);
     printf("\n Enter how many cols?");
     scanf("%d",&n);

     printf("\n Input matrix");
     for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
       {
           printf("\n Enter element %d%d",i+1,j+1);
           scanf("%d",&mat[i][j]);
        }
     }

     printf("\n\n Given matrix is\n");
     for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
            printf("%d\t",mat[i][j]);
       printf("\n");
    }

    for(i=0;i<m;i++)
   {
       for(j=0;j<n;j++)
      {
          if(mat[i][j]!=mat[j][i])
          {
              flag=0;
              break;
          }
       }
       printf("\n");
    }

    if(flag==1)
       printf("\n Matrix is Symmetric");
    else
       printf("\n Matrix is not symmetric");

      return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.