Transpose of a Matrix in C++
Here you will get the program code of Transpose of a Matrix in C++ programming.
Transposing a matrix is the process, of exchanging the values of the rows and columns of a matrix.
For Example:-
Matrix values:
1 2 3
4 5 6
Matrix after Transpose :
1 4
2 5
3 6
Example code of Transpose of a Matrix in C++
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 | //Transpose of a Matrix in C++ #include<iostream> using namespace std; #define ROW 2 #define COL 3 int main() { int mat[ROW][COL], transpose[COL][ROW]; int i, j; cout<<"Enter the elements of matrix:\n"; for (i = 0; i < ROW; i++) for (j = 0; j < COL; j++) cin>>mat[i][j]; cout<<"\nEntered Matrix:\n"; for (i = 0; i < ROW; i++) { for (j = 0; j < COL; j++) cout<<mat[i][j]<<" "; cout<<endl; } for (i = 0; i < ROW; i++) for (j = 0; j < COL; j++) transpose[j][i] = mat[i][j]; cout<<"\nMatrix after Transpose :\n"; for (i = 0; i < COL; i++) { for (j = 0; j < ROW; j++) cout<<transpose[i][j]<<" "; cout<<endl; } return 0; } |
Output
Other Similar Programs
Find Highest and Lowest Element of a Matrix in C++
Check out our other C++ programming Examples