Check the Symmetric matrix with C.
#include <stdio.h>
int main()
{
int A[3][3]; // Original matrix
int B[3][3]; // Transpose matrix
int row, col, isSymmetric;
/* Input elements in matrix A from user */
printf("Enter elements in matrix of 3 3x3: \n");
for (row = 0; row < 3; row++)
{
for (col = 0; col < 3; col++)
{
scanf("%d", &A[row][col]);
}
}
for (row = 0; row < 3; row++)
{
for (col = 0; col < 3; col++)
{
B[row][col] = A[col][row];
}
}
isSymmetric = 1;
for (row = 0; row < 3 && isSymmetric; row++)
{
for (col = 0; col < 3; col++)
{
if (A[row][col] != B[row][col])
{
isSymmetric = 0;
break;
}
}
}
/*
* If the given matrix is symmetric.
*/
if (isSymmetric == 1)
{
printf("\nThe given matrix is Symmetric matrix: \n");
for (row = 0; row < 3; row++)
{
for (col = 0; col < 3; col++)
{
printf("%d ", A[row][col]);
}
printf("\n");
}
}
else
{
printf("\nThe given matrix is not Symmetric matrix.");
}
return 0;
}
Output
Enter elements in matrix of size 3x3:
1 2 3
2 4 5
3 5 8
The given matrix is Symmetric matrix:
1 2 3
2 4 5
3 5 8
0 Comments