thevals

1234

Nov 25th, 2021 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void ArrayCreate(double*** arr, int Dim1, int Dim2);
  4. //double** func(int Dim1, int Dim2);
  5. int main() {
  6.     double** a;
  7.     int n = 3, m = 3;
  8.  
  9.     a = (double**)calloc(n, sizeof(double*));
  10.     for (int i = 0; i < n; i++) a[i] = (double*)calloc(m, sizeof(double));
  11.     a[0][2] = 3.14;
  12.     for (int i = 0; i < n; i++) {
  13.         for (int j = 0; j < m; j++) a[i][j] = 3.14 + 2.0 * i;
  14.     }
  15.     for (int i = 0; i < n; i++) {
  16.         for (int j = 0; j < m; j++) printf("%1.9f ", a[i][j]);
  17.         printf("\n");
  18.     }
  19.     for (int i = 0; i < n; i++) free(a[i]);
  20.     free(a);
  21.  
  22.     double** b;
  23.     ArrayCreate(&b, n, m);
  24.     for (int i = 0; i < n; i++) {
  25.         for (int j = 0; j < m; j++) b[i][j] = 3.14 + 2.0 * i;
  26.     }
  27.     for (int i = 0; i < n; i++) {
  28.         for (int j = 0; j < m; j++) printf("%1.9f ", b[i][j]);
  29.         printf("\n");
  30.     }
  31.     for (int i = 0; i < n; i++) free(b[i]);
  32.     free(b);
  33.     /*double** c = func(n, m);
  34.     c[0][2] = 3.14;
  35.     printf("%f", c[0][2]);*/
  36. }
  37.  
  38. /*double** func(int Dim1, int Dim2) {
  39.     double** arr = (double**)calloc(Dim1, sizeof(double*));
  40.     for (int i = 0; i < Dim1; i++) arr[i] = (double*)calloc(Dim2, sizeof(double));
  41.     return arr;
  42. }
  43. */
  44.  
  45. void ArrayCreate(double*** arr, int Dim1, int Dim2) {
  46.     *arr = (double**)calloc(Dim1, sizeof(double*));
  47.     for (int i = 0; i < Dim1; i++) (*arr)[i] = (double*)calloc(Dim2, sizeof(double));
  48. }
  49.  
Add Comment
Please, Sign In to add comment