Advertisement
Guest User

nrComplexe

a guest
Jun 20th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. typedef struct complex
  7. {
  8.     float Re, Im;
  9. }complex;
  10.  
  11.  
  12. complex conjugat(complex x)
  13. {
  14.     complex temp;
  15.     temp.Re = x.Re;
  16.     temp.Im = (-2)*x.Im;
  17.  
  18.     return (temp);
  19. }
  20.  
  21. complex add(complex z1, complex z2)
  22. {
  23.     complex temp;
  24.     temp.Re = z1.Re+z2.Re;
  25.     temp.Im = z1.Im+z2.Im;
  26.  
  27.     return (temp);
  28. }
  29.  
  30. complex sub(complex z1, complex z2)
  31. {
  32.     complex temp;
  33.     temp.Re = z1.Re - z2.Re;
  34.     temp.Im = z1.Im - z2.Im;
  35.  
  36.     return (temp);
  37. }
  38.  
  39. complex prod(complex z1, complex z2)
  40. {
  41.     complex temp;
  42.     temp.Re = (z1.Re)*(z2.Re)-(z1.Im)*(z2.Im);
  43.     temp.Im = (z1.Re)*(z2.Im)+(z1.Im)*(z2.Re);
  44.  
  45.     return (temp);
  46. }
  47.  
  48. double mod(complex z)
  49. {
  50.     double temp = sqrt(pow(z.Re,2)+pow(z.Im,2));
  51.     return (temp);
  52. }
  53.  
  54. void afiseazaNrComplex(complex z)
  55. {
  56.     printf("%f + %fi",z.Re, z.Im);
  57. }
  58.  
  59. int main()
  60. {
  61.     complex z1 = {2,5}, z2 = {4,5};
  62.     complex z3 = prod(z1,z2);
  63.     afiseazaNrComplex(z3);
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement