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.
Example
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
- Input the Matrix from the User.
- Find the Transpose of the Matrix.
- 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #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.