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
Post a Comment
Please do not spam any link