Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c51e79a

Browse files
authoredJun 10, 2024··
Create Transpose_matrix.cpp
1 parent 4deaef4 commit c51e79a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 

‎2D_Array/Transpose_matrix.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
#define N 4
5+
6+
class solution{
7+
void transpose(int A[][N], int B[][N])
8+
{
9+
int i, j;
10+
for (i = 0; i < N; i++)
11+
for (j = 0; j < N; j++)
12+
B[i][j] = A[j][i];
13+
}
14+
};
15+
16+
17+
int main()
18+
{
19+
solution s;
20+
int A[N][N] = { { 1, 1, 1, 1 },
21+
{ 2, 2, 2, 2 },
22+
{ 3, 3, 3, 3 },
23+
{ 4, 4, 4, 4 } };
24+
25+
26+
int B[N][N], i, j;
27+
28+
29+
s.transpose(A, B);
30+
31+
cout << "Result matrix is \n";
32+
for (i = 0; i < N; i++) {
33+
for (j = 0; j < N; j++)
34+
cout << " " << B[i][j];
35+
36+
cout << "\n";
37+
}
38+
return 0;
39+
}
40+

0 commit comments

Comments
 (0)
Please sign in to comment.