Skip to content

Commit

Permalink
Create Transpose_matrix.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashraghuvans authored Jun 10, 2024
1 parent 4deaef4 commit c51e79a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 2D_Array/Transpose_matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#include <bits/stdc++.h>
using namespace std;
#define N 4

class solution{
void transpose(int A[][N], int B[][N])
{
int i, j;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
B[i][j] = A[j][i];
}
};


int main()
{
solution s;
int A[N][N] = { { 1, 1, 1, 1 },
{ 2, 2, 2, 2 },
{ 3, 3, 3, 3 },
{ 4, 4, 4, 4 } };


int B[N][N], i, j;


s.transpose(A, B);

cout << "Result matrix is \n";
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
cout << " " << B[i][j];

cout << "\n";
}
return 0;
}

0 comments on commit c51e79a

Please sign in to comment.