Input a matrix and determine whether it is symmetric matrix or not .
NB: A matrix is called a symmetric matrix when i, j th element is equal to j,i th element for all i and j .#include <stdio.h>
#include <conio.h>
void main ( )
{
int n1[3][3], i, j, f = 0;
clrscr ( );
printf ("\n\t\t\t Enter numbers in a matrix");
printf("\n\t\t\t____________________________\n");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++)
{
printf("\n\t\t\t Position [%d] [%d]..:",i,j); scanf ("%d", &n1[i][ j] );
}
}
clrscr ( );
printf("\n\n\n\n\t\t\t Matrix\n\t\t\t______________\n\n\t\t\t");
for ( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
printf ("%3d ", n1[i][ j] );
}
printf ("\n\t\t\t");
}
for( i = 0; i < 3; i++ )
{
for ( j = 0; j < 3; j++ )
{
if ( n1[i][ j] != n1[ j][i] )
f = 1;
}
}
if( f == 0 )
{
printf("\n\n\n\n\t\t The matrix is symmetric matrix.");
}
else
{
printf("\n\n\n\n\t\t The matrix is not symmetric matrix.");
}
getch ( );
}
Click here to contact us
No comments:
Post a Comment