Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. double* alloc_real_table_1D(int lenght)
  5. {
  6.     double* x=(double*)malloc(sizeof(double)*lenght);
  7.     return x;
  8. }
  9.  
  10. double** alloc_real_table_2D(int M, int N)
  11. {
  12.     //rzutowanie typu malloca na to przed =
  13.     double** x=(double**)malloc(sizeof(double*)*M);
  14.     for(int i=0; i<M; i++)
  15.     {
  16.         x[i]= (double*)malloc(sizeof(double)*N);
  17.     }
  18.     return x;
  19. }
  20.  
  21. double*** alloc_real_table_3D(int M, int N, int O)
  22. {
  23.     double*** x= (double***)malloc(sizeof(double**)*M);
  24.     for(int i=0; i<M; i++)
  25.     {
  26.         x[i]= (double**)malloc(sizeof(double*)*N);
  27.         for(int j=0; j<N; j++)
  28.         {
  29.             x[i][j]= (double*)malloc(sizeof(double)*O);
  30.         }
  31.     }
  32.     return x;
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38.     double* x=alloc_real_table_1D(5);
  39.     x[3]=5;
  40.     printf("%lf",x[2]);
  41.     alloc_real_table_3D(10,20,30);
  42.     alloc_real_table_2D(10,20);
  43.     free(x);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement