Transpose of matrix

#include <iostream>
using namespace std;
const int MAX = 100;

void transpose(int arr[][MAX], int m, int n){
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n; j++){
            cout<<arr[j][i]<<" ";
        }
        cout<<endl;
    }
}

int main(){
    int arr[4][MAX] = {{1,2,4,5},
                       {5,8,5,9},
                       {7,8,9,4},
                       {4,8,9,6}};
                
    transpose(arr,4,4);
    return 0;
}

    Leave a Reply

    Your email address will not be published.

    Need Help?