// Simple use of a dynamic matrix
#include <iostream>
using namespace std;

int main(){

  // Get the number of rows and columns
  int nRow, nCol;
  cout << "A Matrix Transposer (version 1.0)" << endl;
  cout << "Input number of rows   : ";
  cin >> nRow;
  cout << "Input number of columns: ";
  cin >> nCol;

  // Setup the matrix
  int **matrix = new int * [nRow];
  for (int i = 0; i < nRow; i++)
     matrix[i] = new int [nCol];

  // Get the elements (row wise)
  cout << endl << "Input the elements of the matrix:" << endl;
  for (int i = 0; i < nRow; i++)
    for (int j = 0; j < nCol; j++)
       cin >> matrix[i][j];

  // Print out the transpose matrix
  cout << endl << "Its transpose is:" << endl;
  for (int i = 0; i < nCol; i++){
    for (int j = 0; j < nRow; j++){
       cout << matrix[j][i] << " ";
    }
    cout << endl;
  }

  // Cleanup the memory
  for (int i = 0; i < nRow; i++){
    delete[] matrix[i];
  }
  delete[] matrix;

  return 0;
}
