transpose function example in c++
#include <iostream>
using namespace std;
void transpose(int arr[3][3]) {
int temp;
for (int i = 0; i < 3; i++) {
for (int j = i; j < 3; j++) {
temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
}
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
transpose(arr);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}