Advertisement
H-a-y-K

Untitled

Nov 15th, 2020
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. typedef struct
  4. {
  5.      double real;
  6.      double imm;
  7. } Complex;
  8.  
  9. Complex product(Complex c1, Complex c2)
  10. {
  11.       Complex result;
  12.  
  13.       result.real = c1.real * c2.real - c1.imm * c2.imm;
  14.       result.imm = c1.real * c2.imm + c1.imm * c2.real;
  15.  
  16.      return result;
  17. }
  18.  
  19. void print_complex(Complex c)
  20. {
  21.       printf("%d + %di", c.real, c.imm);
  22. }
  23.  
  24. int main()
  25. {
  26.      Complex c1, c2, c3;
  27.  
  28.      c1.real = 4;
  29.      c1.imm = 5; // 4 + 5i
  30.  
  31.      // ...
  32.      // c2 = 8 + 6i
  33.      // c3 = 0
  34.  
  35.      Complex nums[] = {c1, c2, c3};
  36.  
  37.      Complex prod;
  38.      prod.real = 1;
  39.      prod.imm = 0;
  40.  
  41.      for (int i = 0; i < 3; i++)
  42.            prod = product(prod, nums[i]);
  43.  
  44.      print_complex(prod); // dovrebbe essere 0 + 0i
  45.  
  46.      return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement