Sunday, 7 April 2013

Matrix symmetricity in c program with output

CHECKING FOR SYMMETRICITY IN MATRIX


#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],I[3][3]={{1,0,0},{0,1,0},{0,0,1}},m,n,sym=0,i,j,k;
clrscr();
printf("\n\t\tChecking For Symmetrical Matrix");
printf("\nEnter the order of the square matrix:");
scanf("%d%d",&m,&n);
printf("\nEnter the elements of the matrix:\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
//Symmetric
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
if(a[i][j]==a[j][i])
{
sym=1;
}
else
{
sym=0;
break;
}
}
if(sym==0)
break;
}
//a*T(a)
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
b[i][j]=0;
for(k=1;k<=m;k++)
{
b[i][j]=b[i][j]+(a[i][k]*a[j][k]);
}
}
}
printf("\nGiven Matrix is:\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",a[i][j]);
}
printf("\n");
}
printf("\nTranspose of the given matrix is:\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",a[j][i]);
}
printf("\n");
}
if(sym==1)
printf("\nGiven matrix is SYMMETRIC....!");
else
printf("\nGiven matrix is NOT SYMMETRIC....!");
getch();
}
 
Output:

Checking For Symmetrical Matrix

Enter the order of the square matrix:2 2

Enter the elements of the matrix:
1
2
2
1

Given Matrix is:

                          1       2
                          2       1

Transpose of the given matrix is:

                          1       2
                          2       1

Given matrix is SYMMETRIC....!

No comments:

Post a Comment