Skip to content

Commit

Permalink
Merge pull request #301 from irvn0x/main
Browse files Browse the repository at this point in the history
add transpose matrix in c++
  • Loading branch information
MSubhajitIND authored Oct 12, 2023
2 parents 8f32cb6 + b778ec6 commit e259d25
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions transposeMatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
using namespace std;

const int MAX = 10;

void transposeMatrix(int matrix[MAX][MAX], int row, int col) {
int transposed[MAX][MAX];

// Moving matrix elements to the transposed matrix.
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
transposed[j][i] = matrix[i][j];
}
}

// Displaying the transposed matrix.
cout << "Transposed Matrix:" << endl;
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
cout << transposed[i][j] << " ";
}
cout << endl;
}
}

int main() {
int row = 3, col = 3;
int matrix[MAX][MAX] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};

// Calling a function to perform the transpose.
transposeMatrix(matrix, row, col);

return 0;
}

0 comments on commit e259d25

Please sign in to comment.