Advertisement
Guest User

Untitled

a guest
Oct 13th, 2012
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define M_ROWS 20
  5. #define M_COLS 30
  6. #define D_FORMAT "%8.3f"
  7.  
  8. void printDoubleMatrix(double **mtx, int rows, int cols)
  9. {
  10.     printf("%8.3f", mtx[2][2]);
  11. }
  12.  
  13. void generateMatrix(double ***mtx, int rows, int cols)
  14. {
  15.     *mtx = (double **)calloc(rows, sizeof(double *));
  16.     int i = 0, j = 0;
  17.  
  18.     if(!mtx)
  19.     {
  20.         printf("mtx == NULL\n");
  21.         return;
  22.     }
  23.  
  24.     for(i = 0; i < rows; i++)
  25.     {
  26.         (*mtx)[i] = (double *)calloc(cols, sizeof(double));
  27.    
  28.         for(j = 0; j < cols; j++)
  29.         {
  30.             (*mtx)[i][j] = (i * j - 1);
  31.         }
  32.     }
  33. }
  34.  
  35. int main(int argc, char* argv[])
  36. {
  37.     double **Matrix = NULL;
  38.     generateMatrix(&Matrix, 4, 5);
  39.     printDoubleMatrix(Matrix, 4, 5);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement