100% C program to find if a matrix is symmetric or not
//program to find if a matrix is symmetric or not
#include <stdio.h>
void main()
{
int i,j,m,n,a[20][20],count=0;;
printf("\n this program will take a matrix as input and print if is symmetric or not\n");
printf("\n enter no of rows & columns each in 1 to 20:");
scanf("%d%d",&m,&n);
if (m!=n)
{
printf("\n the matrix is not square & so is not symmetric");
}
else
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\n enter a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\n given matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
printf("\n \n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=a[j][i])
{
printf("\n given matrix is not symmetric");
exit(0);
}
else
{
count=count+1;
}
}//end of j for loop
}// end of i for loop
if(count==m*n)
{
printf("\n given matrix is symmetric");
}
}//end of the 1st else
}// end of main()
#include <stdio.h>
void main()
{
int i,j,m,n,a[20][20],count=0;;
printf("\n this program will take a matrix as input and print if is symmetric or not\n");
printf("\n enter no of rows & columns each in 1 to 20:");
scanf("%d%d",&m,&n);
if (m!=n)
{
printf("\n the matrix is not square & so is not symmetric");
}
else
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\n enter a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\n given matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
printf("\n \n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=a[j][i])
{
printf("\n given matrix is not symmetric");
exit(0);
}
else
{
count=count+1;
}
}//end of j for loop
}// end of i for loop
if(count==m*n)
{
printf("\n given matrix is symmetric");
}
}//end of the 1st else
}// end of main()
ఔట్పుట్ తెరమీద
this program will take a matrix as input and print if is symmetric or not
enter no of rows & columns each in 1 to 20:2 2
enter a[0][0]:1
enter a[0][1]:2
enter a[1][0]:3
enter a[1][1]:4
given matrix is:
1 2
3 4
given matrix is not symmetric
enter no of rows & columns each in 1 to 20:2 2
enter a[0][0]:1
enter a[0][1]:2
enter a[1][0]:3
enter a[1][1]:4
given matrix is:
1 2
3 4
given matrix is not symmetric
మరోసారి చేస్తే ఔట్పుట్ తెరమీద
enter no of rows & columns each in 1 to 20:2 3
the matrix is not square & so is not symmetric
the matrix is not square & so is not symmetric
మరోసారి చేస్తే ఔట్పుట్ తెరమీద
this program will take a matrix as input and print if is symmetric or not
enter no of rows&columns each in 1 to 20:2 2
enter a[0][0]:1
enter a[0][1]:0
enter a[1][0]:0
enter a[1][1]:1
given matrix is:
1 0
0 1
given matrix is symmetric
enter no of rows&columns each in 1 to 20:2 2
enter a[0][0]:1
enter a[0][1]:0
enter a[1][0]:0
enter a[1][1]:1
given matrix is:
1 0
0 1
given matrix is symmetric
గమనిక A' అంటే ట్రాన్స్పోస్ అనుకుంటే , A-A' చేసి అన్నీ సున్నాలేవస్తున్నాయా అని కూడా చూడవచ్చు ;
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.