Program to find if a 3 by 3 square matrix is symmetric

A symmetric matrix is a square matrix that is equal to its transpose. Let A be a symmetric matrix.
Then,
A = AT

In this program, we need to check whether the given square matrix is symmetric or not. We will follow the steps given below.

  • Step 1 – Accepts a square matrix as input
  • Step 2 – Create a transpose of a matrix and store it in an array
  • Step 3 – Check if input matrix is equal to its transpose or not
    If it is equal, then the input square matrix is symmetric.

Here it goes…

#include
#include

void main(){
 int arr[10][10], arrT[10][10];
 int i,j;
 clrscr();
 printf("Enter the 3x3 matrix:\n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   printf("Enter the element arr[%d][%d] : ",i,j);
   scanf("%d",&arr[i][j]);
  }
 }
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   arrT[j][i] = arr[i][j];
  }
 }

 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   if(arr[i][j] == arrT[i][j]){
    continue;
   }
   else{
    printf("\nInput matrix is not a symmetric matrix.");
    getch();
    exit(0);
   }
  }
 }
 printf("\nInput matrix is a symmetric matrix");
 getch();
}

Output:

Enter the 3x3 matrix:
Enter the element arr[0][0] : 1
Enter the element arr[0][1] : 2
Enter the element arr[0][2] : 3
Enter the element arr[1][0] : 2
Enter the element arr[1][1] : 4
Enter the element arr[1][2] : -5
Enter the element arr[2][0] : 3
Enter the element arr[2][1] : -5
Enter the element arr[2][2] : 6

Input matrix is a symmetric matrix

You may also like...

14 Responses

  1. Anonymous says:

    Thanks a lot!!!!!!!!

  2. Anonymous says:

    thanks for the program really helpful!!! cheers!!!!

  3. Anonymous says:

    Thanks

  4. Anonymous says:

    i have a simple solution for this program

  5. LearnCOnline says:

    Thanks… Would be highly appreciated if you provide us with the solution.
    Regards.

  6. Anonymous says:

    tht is else shud be in t same pair of braces

  7. Anonymous says:

    we can also do without taking transpose.
    just write directly a[i][j]=a[j][i]..

  8. Anonymous says:

    thank you

  9. Anonymous says:

    it is very much helpfull to us

  10. Anonymous says:

    logic absolutely right….thank you…..

  11. Anonymous says:

    Thanks to explain this in such a delecate manner!

  12. Anonymous says:

    thanks

  13. Anonymous says:

    your program is very easy

Leave a Reply

Your email address will not be published. Required fields are marked *