Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. struct Matrix
  2. {
  3.     double** matrix;
  4.     int n;
  5.     int m;
  6. };
  7.  
  8. struct Matrix getMatrix(int n, int m)
  9. {
  10.     struct Matrix result;
  11.  
  12.     result.n = n;
  13.     result.m = m;
  14.  
  15.     result.matrix = (double*)calloc(n, sizeof(double*));
  16.  
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         double* arr = (double*)calloc(m, sizeof(double*));
  20.         result.matrix[i] = arr;
  21.     }
  22.  
  23.     return result;
  24. }
  25.  
  26. int main()
  27. {  
  28.     struct Matrix matrix1 = getMatrix(2, 3);
  29.     struct Matrix matrix2 = getMatrix(3, 4);
  30.  
  31.     free(&matrix1);
  32.     free(&matrix2);
  33.  
  34.     getchar();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement