#include <stdlib.h>



double ** alloc_matrix(int n, int m) {

   double ** M = (double**)calloc(n,sizeof(double*));

   int i;

   for(i=0; i < n; ++i) M[i] = (double*)calloc(m,sizeof(double));

   return M;

}



void free_matrix(double** M, int n) {

   int i;

   for(i = 0; i < n; ++i) free(M[i]);         

   free(M);

}



double ** matrix_transpose(const double *const * M, int n, int m) {

   double ** R = alloc_matrix(m,n);

   int i,j;

   for(i=0; i < n; ++i) 

      for(j=0; j <  m; ++j) R[j][i] = M[i][j];



   return R;

}



#include <stdio.h>



void matrix_print(const double * const * M, int n, int m) {

   int i,j;

   for(i=0; i<n; ++i) {

      for(j=0; j<m; ++j) printf("%9.2lf ",M[i][j]);

      printf("\n");

   }

}



