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 find out the roots of a Quadratic Equation and also test for Real and Complex roots

 C Program to find out the roots of a Quadratic Equation  and also test for Real and Complex roots.       In this example, we will calculate the roots of the quadratic equation by testing for real and complex roots. We can test real and complex roots by checking these conditions : If b 2  −4 ac  < 0, then there are no real roots. If b 2  −4 ac  = 0, then both the roots are equal. If b 2  −4 ac  > 0, then roots are real and distinct.   PROGRAM TO FIND OUT THE ROOTS OF A QUADRATIC EQUATION. #include <stdio.h> #include <conio.h> #include <math.h> int   main () {      int   a , b , c , d ;      float   x , y ;      printf ( "Enter coefficient of x^2,x and constant : " );      scanf ( " %d   %d   %d " ,& a ,& b ,& c );      d = b * b ...

C Program to Check Even or Odd Without Modulous and Bitwise Operator

  C Program to Check Even or Odd Without Modulous and Bitwise Operator                   In this example we will check even or odd without Modulous Operator. To do this program we should know what is even and odd number.                   Even Number: Even numbers are those numbers which are divisible by 2. That means if we divide a number by 2 and if its remainder appears 0 then it is an even number.                                 For Example: 2,4,6,8,10,12,.... are all even numbers.                              ...

C Program to find the sum of the series 1^2+2^2+3^2+…..+n^2

C Program to find the sum of the series  1 2 +2 2 +3 2 +…..+n 2 Enter the end limit at the runtime.       In this example, we calculate the sum of the above mentioned series till the end-limit entered by the user. We have used built-in function pow(x,y) to find the power of the given number.     Here in the output we have entered the value of end-limit as number 7 which gives a sum of 140.    PROGRAM #include <stdio.h> #include <math.h> #include <conio.h> void   main () {      int  n,sum= 0 ,i;      printf ( "Enter the end limit :" );      scanf ( " %d " ,&n);      for (i= 1 ;i<=n;i++)     {         sum=sum+ pow (i, 2 );     }      printf ( "Sum of the series is :  %d " ,sum);  ...

C Program to Generate Multiplication Table according to User Choice.

 C Program to Generate Multiplication Table according to User Choice.     In this program, we will learn how to print a multiplication table according to any positive number entered by the user. This program uses for loop to solve this problem.  C PROGRAM TO GENERATE MULTIPLICATION TABLE: # include < stdio.h > # include < conio.h > int   main () {      int   i , num , res = 0 ;      printf ( "\n Enter the multplication table you want :  " );      scanf ( " %d " ,& num );      printf ( "\n\n\n\t MULTIPLICATION TABLE OF  %d \t" , num );      printf ( "\n -------------------------------------------------- \n" );      for ( i = 1 ; i <= 10 ; i ++)      {          res = num * i ;       ...

C Program to Multiply two Matrices

 C Program to Multiply two Matrices.     In this example, we will calculate the product of the two matrices allowing the user to enter their required number of rows and columns. In matrix multiplication the number of columns, in the first matrix must be equal to the number of  rows in the second matrix, otherwise multiplication is not possible. The product will have the number of rows of the first matrix and the number of columns of the second matrix.     Here in the output we have taken two matrices of order 2x3 and 3x2. The resulting matrix after calculating the product will be of the order 2x2. PROGRAM #include <stdio.h> #include <conio.h> void   main () {      int   row1 , row2 , column1 , column2 , i , j , k ;      int   a [ 10 ][ 10 ], b [ 10 ][ 10 ], mul [ 10 ][ 10 ];      printf ( "Enter the row size of the 1st Matrix :...