In this tutorial you will learn about the C Program to check Matrix is a Symmetric Matrix and its application with practical example.
C Program to check Matrix is a Symmetric Matrix
In this tutorial, we will learn to create a C program that will check the Matrix is a Symmetric Matrix using C programming.
Prerequisites
Before starting with the tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variables for the program. 2. Taking the input size of matrix. 3. Taking the input elements of matrix. 4. Checking the given Matrix is a Symmetric Matrix. 5. Printing the result. 6. End Program. |
Program to check the matrix:-
In this tutorial, we will check the matrix is symmetric or not with the help of the c programming. First, we will take the size and the elements of the matrix. Then we will check transpose the matrix using the code. Now we will compare the two matrices and if they are symmetric or not. Then will print the output to the user.
Program:-
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 |
/* C Program to check Matrix is a Symmetric Matrix or Not */ #include<stdio.h> int main()//body of the main function { //declaring the required variables for the program. int i, j, rw, clm, a[10][10], b[10][10], Count = 1; //i,j = it will hold the integer value for the rows and the columns. //Taking the size of the matrix in form of rows and columns. printf("\n Please Enter Number of rows and columns : "); scanf("%d %d", &i, &j); //taking the Elements of the matrix. printf("\n Please Enter the Matrix Elements \n"); for(rw = 0; rw < i; rw++) { for(clm = 0;clm < j;clm++) { scanf("%d", &a[rw][clm]); } } //Transpose of matrix for(rw = 0; rw < i; rw++) { for(clm = 0;clm < j; clm++) { b[clm][rw] = a[rw][clm]; } } for(rw = 0; rw < i; rw++) { for(clm = 0; clm < j; clm++) { if(a[rw][clm] != b[rw][clm]) { Count++; break; } } } //Printing the output of the matrix. if(Count == 1) { printf("\n The Matrix that you entered is a Symmetric Matrix "); } else { printf("\n The Matrix that you entered is Not a Symmetric Matrix "); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- a[10][10]= it will hold the integer value.
- rw = it will hold the integer value for loop.
- cl = it will hold the integer value for loop.
- i= it will hold the input integer value for rows.
- j= it will hold the input integer value for columns.
Taking the size and the elements of the matrix from the user.
Checking the matrix is symmetric or not a symmetric matrix.
Printing the Matrix is symmetric or not.