# Symmetric Matrix C Program

By | October 28, 2016

Learn How To Find if a Matrix is a Symmetric Matrix in C Programming. The following C programs use functions, arrays and Transpose concepts to check if a Square Matrix is Symmetric or not.

#### What is a Symmetric Matrix?

A Symmetric Matrix is the one that is always equivalent to its Transpose. A Square Matrix that is identical to its Transpose Matrix is known as a Symmetric Matrix. Only square matrices are symmetric as equal matrices have equal dimensions.

Input Matrix

1 5 7
5 4 9
7 9 4

#### Transpose Matrix

1 5 7
5 4 9
7 9 4

Since the Input Matrix and the Transpose are equivalent, the Matrix is Symmetrical.

#### Algorithm To Find Symmetric Matrix

1. Input the Matrix from the User.
2. Find the Transpose of the Matrix.
3. If the Input Matrix and its Transpose are same, then the Matrix is Symmetrical.

#### Method 1: C Program To Find if a Matrix is a Symmetric Matrix or Not without Functions

```#include<stdio.h>

int main()
{
int arr[5][5];
int row, column, row_limit, column_limit, temp = 0;
printf("Enter the Number of Rows:\t");
scanf("%d", &row_limit);
printf("Enter the Number of Columns:\t");
scanf("%d", &column_limit);
printf("\nEnter the Elements of the Square Matrix of Dimension [%d][%d]\n", row_limit, column_limit);
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < column_limit; column++)
{
printf("Enter Element:\t");
scanf("%d", &arr[row][column]);
}
}
printf("\nEntered Matrix\n");
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < column_limit; column++)
{
printf("%d\t", arr[row][column]);
}
printf("\n");
}
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < column_limit; column++)
{
if(arr[row][column] != arr[column][row])
{
temp = 1;
break;
}
}
}
if(temp == 1)
{
printf("\nThe Entered Matrix is Not A Symmetric Matrix\n");
}
else
{
printf("\nThe Entered Matrix is A Symmetric Matrix\n");
}
return 0;
}```

#### Method 2: C Program To Find Symmetric Matrix using Array and Transpose

```#include<stdio.h>

int main()
{
int arr[10][10], transpose[10][10];
int row_limit, column_limit, row, column;
printf("Enter the Number of Rows:\t");
scanf("%d", &row_limit);
printf("Enter the Number of Columns:\t");
scanf("%d", &column_limit);
printf("\nEnter the Elements of the Square Matrix of Dimension [%d][%d]\n", row_limit, column_limit);
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < column_limit; column++)
{
printf("Enter Element:\t");
scanf("%d", &arr[row][column]);
}
}
for(row = 0 ; row < row_limit ; row++)
{
for(column = 0; column < column_limit; column++)
{
transpose[column][row] = arr[row][column];
}
}
if(row_limit == column_limit)
{
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < row_limit; column++)
{
if(arr[row][column] != transpose[row][column])
{
break;
}
}
if(column != row_limit)
{
break;
}
}
if(row == row_limit)
{
printf("\nThe Entered Matrix is A Symmetric Matrix\n");
}
}
else
{
printf("\nThe Entered Matrix is Not A Symmetric Matrix\n");
}
return 0;
}```

#### Method 3: C Program To Check Symmetric Matrix using Functions

```#include<stdio.h>

int arr[5][5], transpose[5][5];
int row_limit, column_limit, row, column;

void getmatrix()
{
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < column_limit; column++)
{
printf("Enter Element:\t");
scanf("%d", &arr[row][column]);
}
}
}

void find_transpose()
{
for(row = 0 ; row < row_limit ; row++)
{
for(column = 0; column < column_limit; column++)
{
transpose[column][row] = arr[row][column];
}
}
}

int check()
{
if(row_limit == column_limit)
{
for(row = 0; row < row_limit; row++)
{
for(column = 0; column < row_limit; column++)
{
if(arr[row][column] != transpose[row][column])
{
break;
}
}
if(column != row_limit)
{
break;
}
}
if(row == row_limit)
{
return 0;
}
}
else
{
return 1;
}
}

int main()
{
int result;
printf("Enter the Number of Rows:\t");
scanf("%d", &row_limit);
printf("Enter the Number of Columns:\t");
scanf("%d", &column_limit);
printf("\nEnter the Elements of the Square Matrix of Dimension [%d][%d]\n", row_limit, column_limit);
getmatrix();
find_transpose();
result = check();
if(result == 0)
{
printf("\nThe Entered Matrix is A Symmetric Matrix\n");
}
else
{
printf("\nThe Entered Matrix is Not A Symmetric Matrix\n");
}
return 0;
}```

#### Output

In case you get any compilation errors or any doubts in this C Program To Check if a Matrix is Symmetrical or Not, let us know about it in the comment section below.