Skip to main content

C Program to check if a given square matrix is symmetric or not using function

 C Program to check if a given square matrix is symmetric or not using function.

    In this example, we will check if a given square matrix entered by the user is symmetric or not. Here in the output we have taken a square matrix of 3x3.

PROGRAM TO CHECK IF A GIVEN SQUARE MATRIX IS SYMMETRIC OR NOT USING FUNCTION



#include<stdio.h>
#include<conio.h>
void symmetric(int,int,int [50][50]);
void main()
{
    int row,column,i,j,a[50][50];
    printf("Enter the size of the matrices: ");
    scanf("%d",&row);
    column=row;
    printf("Enter the matrix : ");
    for(i=0;i<row;i++)
    {
        for(j=0;j<column;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    symmetric(row,column,a);
    getch();

}
void symmetric(int r,int c,int f[50][50])
{
    int flag=1,i,j,t[50][50];
    for(j=0;j<c;j++)
    {
        for(i=0;i<r;i++)
        {
            t[i][j]=f[i][j];
            if(t[i][j]!=f[i][j])
            {
                flag=0;
                break;
            }
        }
        if(flag==0)
        {
            printf("The Matrix is Not Symmetric.");
            break;
        }
    }  
    if(flag==1)
    {
        printf("The Matrix is Symmetric.");
    }
    else
    {
        printf("The Matrix is Not Symmetric Matrix.");
    }
    
}


OUTPUT TO CHECK IF A GIVEN SQUARE MATRIX IS SYMMETRIC OR NOT USING FUNCTION

    Enter the size of the matrices: 3

    Enter the matrix : 9

    2

    3

    2

    -1

    -8

    3

    - 8

    0

    The Matrix is Symmetric.


NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

                    You Learn, I Learn together We Learn.

Comments

Popular posts from this blog

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf