Solved programming problem

Finding a matrix is Symmetric or not in C.

Source code

#include <stdio.h>

int main()

{

    int array[100][100],array1[100][100];

    int i,j,n;

    int flag=0;

    printf("Please Enter the row or column number: ");

    scanf("%d",&n);

    printf("Please enter a %d X %d array :
",n,n);

    for(i=0;i<n;i++)   /// using a n X n matrix

    {

        for(j=0;j<n;j++)

        {

            scanf("%d",&array[i][j]);

        }

    }

     for(i=0;i<n;i++)

    {

        for(j=0;j<n;j++)

        {

          array1[i][j]=array[j][i]; /// saving the array row element in the column of the array1 and column to row

        }

    }

      for(i=0;i<n;i++)

    {

        for(j=0;j<n;j++)

        {

          if(array[i][j]!=array1[i][j]) /// checking if the are same or not

          {

              flag=1;break; ///if not then flag value goes to 1.

          }

        }

    }

    if(flag==1) ///if flag value is 1,that means it not a symmetric matrix

    {

        printf("
No
");

    }

    else printf("
Yes
");

    return 0;

}

Output

Please Enter The row & column Number: 3

Please Enter 3 x 3 Element Of the array:

1 7 3

7 4 5

3 5 6

 

Join the discussion

Add your comment