Advertisement
AnindyaBiswas

complex

Jul 27th, 2022
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct ComplexNo
  4. {
  5.     double real;
  6.     double img;
  7. };
  8. typedef struct ComplexNo ComplexNo;
  9.  
  10. struct ComplexArray
  11. {
  12.     ComplexNo **arr;
  13.     int size;
  14. };
  15. typedef struct ComplexArray ComplexArray;
  16.  
  17. void main()
  18. {
  19.     ComplexArray a;
  20.  
  21.     a.arr = (ComplexNo**)malloc(sizeof(ComplexNo*)*3);
  22.    
  23.     for(int i=0;i<3;i++)
  24.     {
  25.         a.arr[i] = (ComplexNo*)malloc(sizeof(ComplexNo));
  26.         a.arr[i]->real = i;
  27.         a.arr[i]->img = i+1;
  28.     }
  29.  
  30.       for(int i=0;i<3;i++)
  31.     {
  32.         printf("%lf + %lfi\n", a.arr[i]->real, a.arr[i]->img);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement