In this tutorial you will learn about the C Program to Find Transpose Of a Matrix and its application with practical example.
C Program to Find Transpose Of a Matrix
In this tutorial, we will learn to create a C program that will find Transpose Of a 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.
What is a matrix?
A matrix is a multidimensional phenomenon and is created with the help of a 2d array having multiple rows and columns.
Algorithm:-
With the help of this program, we can find Transpose Of a Matrix.
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. Creating the <strong>transposing the matrix.</strong> 5. Printing<strong> the transposed matrix</strong>. 6. End Program. |
Program to find Transpose Of a Matrix:-
In this tutorial, we will create a program that will transpose the taken matrix from the user. First, we will take the input size of the matrix and the elements from the user. Then we will use the for loop to traverse the matrix. At last, we will print the transpose of the matrix 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 |
#include <stdio.h> int main() { //Declaring the required variables for the program. int rw, cl, i, j, mt[10][10], trv[10][10]; //rw = it will hold the integer value for the input rows //cl = it will hold the integer value for the input column //Taking the input intger rows and columns value for the program. printf("Enter rows and columns :\n"); scanf("%d%d", &rw, &cl); //Taking the input elements of the matrix printf("Enter elements of the matrix\n"); for (i= 0; i < rw; i++) for (j = 0; j < cl; j++) scanf("%d", &mt[i][j]); for (i = 0;i < rw;i++) for (j = 0; j < cl; j++) trv[j][i] = mt[i][j]; //traspose of the matrix printf("transpose of the matrix:\n"); for (i = 0; i< cl; i++) { for (j = 0; j < rw; j++) //Printing the elements of the transpose matrix. printf("%d\t", trv[i][j]); printf("\n"); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- mt[10][10]= it will hold the integer value.
- rw = it will hold the integer value.
- cl = it will hold the integer value.
- i = it will hold the input integer value for loops.
- j = it will hold the input integer value for loops.
Taking the size and the elements of the matrix from the user.
Traversing the given matrix.
Printing the Traversed Matrix.