# Transpose of a matrix using C++

As we have learned about matrices in our high school mathematics, A matrix is a way of representation. In geometrical view, it’s a linear representation of a vector space formed by the combination of more sufficient no. of linearly independent planes or vectors. In this tutorial, we are going to learn how to find the Transpose of a matrix in C++.

Okay, But what is transpose!

Transpose is a new matrix formed by interchanging each the rows and columns with each other, we can see the geometrical meaning of this transformation as it will rotate orthogonality of the original matrix.

I suggest you read this tutorial too: **How to find transpose of a matrix in C++ Because here the example is clear enough to understand.**

**Why a computer program for this task:**

*First of all, because the computer’s task is to make our life easy**Creating transpose for a small matrix is not much tedious task, but for larger one.. it creates lots of errors and seems hard.**It will be worthy of a computer program to get this job done for us.*

**Pseudo Code**

- First of all, the user will be asked to enter the size of array, and will be stored.
- Two variables m and n will be storing the respective rows and columns.
- using for loop two times, the first one being run for m times and the second loop for n times, will in together store respective items of matrix.
- As we just have to display transpose, we will print the items in reverse order of row and columns.

**Source code: Find the Transpose of a matrix in C++**

**Source code: Find the Transpose of a matrix in C++**

#include <iostream> using namespace std; int main() { static int array[10][10]; int i, j, m, n; cout<<"Enter the order of the matrix \n"; cin>>m>>n; cout<<"Enter the coefiicients of the matrix\n"; for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) { cin>>array[i][j]; } } cout<<"The given matrix is \n"; for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) { cout<<array[i][j]<<" "; } cout<<"\n"; } cout<<"Transpose of matrix is \n"; for (j = 0; j < n; ++j) { for (i = 0; i < m; ++i) { cout<<array[i][j]<<" "; } cout<<"\n"; } }

**Output :**

`Enter the order of the matrix`

`2 2`

`Enter the coefiicients of the matrix`

`1 2`

`3 4`

`The given matrix is`

`1 2`

`3 4`

`Transpose of matrix is`

`1 3`

`2 4`

`Process returned 0 (0x0) execution time : 9.481 s`

`Press any key to continue.`

*Note: This is a sample output for the given source code above when executed on my computer.*

Hope you have got a clear idea on how to find Transpose of a matrix in C++.

**Other useful and related tutorials at CodeSpeedy**

For the further gaining of knowledge about matrix related programs using C++ language, Please have a visit of the following articles.

- Search element in a sorted matrix in C++
- Rotate a Matrix in C++ ( Clockwise and Anticlockwise )
- Print a given matrix in counter-clockwise spiral form in c++
- Find sum of each row and column of a matrix in C++

## Leave a Reply