Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Cpp/Transpose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
#define N 4

// This function stores transpose
// of A[][] in B[][]
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];
}

// Driver code
int main()
{
int A[N][N] = { { 1, 1, 1, 1 },
{ 2, 2, 2, 2 },
{ 3, 3, 3, 3 },
{ 4, 4, 4, 4 } };

// Note dimensions of B[][]
int B[N][N], i, j;

// Function call
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;
}