#include <iostream>
void transposeMatrix(int rows, int cols, int matrix[][3], int result[][3]) {
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
result[j][i] = matrix[i][j];
}
int main() {
int matrix[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int transpose[3][3] = {{0}};
size_t rows = sizeof matrix / sizeof matrix[0];
size_t cols = sizeof matrix[0] / sizeof matrix[0][0];
transposeMatrix(rows, cols, matrix, transpose);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++)
std::cout << transpose[i][j] << " ";
std::cout << "\n";
}
}
/*
run:
1 4 7
2 5 8
3 6 9
*/