Explore

Edit

Edit

Program to find the transpose of a matrix in C, C++, Java and Python | FACE Prep

Published on 09 Mar 2020

Program to find the transpose of a matrix is discussed here. Transpose of a matrix can be performed by exchanging the elements of row by column and the elements of a column by row.

For example:

Input:

1 2 3
4 5 6
7 8 9

output:

1 4 7
2 5 8
3 6 9



Algorithm:

Consider the matrix:

m[0][0] = 10

m[0][1] = 20

m[1][0] = 30

m[1][1] = 40

m[2][0] = 50

m[2][1]= 60

The transpose of the above matrix can be done by this way:

r_m[0][0] = m[0][0] = 10

r_m[0][1] = m[1][0] = 30

r_m[0][2] = m[2][0] = 50

r_m[1][0] = m[0][1] = 20

r_m[1][1] = m[1][1] = 40

r_m[1][2] = m[2][1] = 60

Program to find the transpose of a matrix

Asked in recruitment drive of Wipro.


C
C++
Java
Python 3

Output
Input- Enter number of rows: 3 Enter number of columns: 3 Enter the element: 1 1 1 2 2 2 3 3 3 Input matrix: 1 1 1 2 2 2 3 3 3 Output- Transpose matrix: 1 2 3 1 2 3 1 2 3

Recommended Programs