Skip to content

Commit f36e21c

Browse files
Matrix Transpose in C++
Created folder for matrix problems and added code for transpose of a given matrix in C++
1 parent ac812fc commit f36e21c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Matrix/MatrixTranspose.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int a[10][10], transpose[10][10], row, column, i, j;
6+
7+
cout << "Enter rows and columns of matrix: ";
8+
cin >> row >> column;
9+
10+
cout << "\nEnter elements of matrix: " << endl;
11+
12+
for (int i = 0; i < row; ++i) {
13+
for (int j = 0; j < column; ++j) {
14+
cout << "Enter element a" << i + 1 << j + 1 << ": ";
15+
cin >> a[i][j];
16+
}
17+
}
18+
19+
cout << "\nEntered Matrix: " << endl;
20+
for (int i = 0; i < row; ++i) {
21+
for (int j = 0; j < column; ++j) {
22+
cout << " " << a[i][j];
23+
if (j == column - 1)
24+
cout << endl << endl;
25+
}
26+
}
27+
28+
for (int i = 0; i < row; ++i)
29+
for (int j = 0; j < column; ++j) {
30+
transpose[j][i] = a[i][j];
31+
}
32+
33+
cout << "\nTranspose of Matrix: " << endl;
34+
for (int i = 0; i < column; ++i)
35+
for (int j = 0; j < row; ++j) {
36+
cout << " " << transpose[i][j];
37+
if (j == row - 1)
38+
cout << endl << endl;
39+
}
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)