Guest User

Untitled

a guest
Jun 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct Zespolone
  4. {
  5.   int re;
  6.   int im;
  7. };
  8.  
  9. void suma(struct Zespolone a, struct Zespolone b);
  10. void roznica(struct Zespolone a, struct Zespolone b);
  11. void iloczyn(struct Zespolone a,struct Zespolone b);
  12. void iloraz(struct Zespolone a,struct Zespolone b);
  13. struct Zespolone* suma_wsk(struct Zespolone a, struct Zespolone b);
  14. struct Zespolone* roznica_wsk(struct Zespolone a,struct Zespolone b);
  15. struct Zespolone* iloczyn_wsk(struct Zespolone a,struct Zespolone b);
  16. struct Zespolone* iloraz_wsk(struct Zespolone a,struct Zespolone b);
  17. int main()
  18. {
  19.     struct Zespolone cp1,cp2;
  20.     scanf("%d %d %d %d",&cp1.re,&cp1.im,&cp2.re,&cp2.im);
  21.  
  22. }
  23. void suma(struct Zespolone a, struct Zespolone b)
  24. {
  25.     a.re += b.re;
  26.     a.im += b.im;
  27. }
  28. void roznica(struct Zespolone a, struct Zespolone b)
  29. {
  30.     a.re -= b.re;
  31.     a.im -= b.im;
  32. }
  33. void iloczyn(struct Zespolone a, struct Zespolone b)
  34. {
  35.     int temp_hld=a.re;
  36.     a.re = a.re*b.re - a.im*b.im;
  37.     a.im = temp_hld*b.im + a.im*b.re;
  38. }
  39. void iloraz(struct Zespolone a,struct Zespolone b)
  40. {
  41.     if (b.re == 0 && b.im == 0) printf("ERROR! Division by zero.\n");
  42.     else
  43.     {
  44.         a.re = (a.re*b.re + a.im*b.im)/(b.re*b.re + b.im*b.im);
  45.         a.im = (a.im*b.re - a.re*b.im)/(b.re*b.re + b.im*b.im);
  46.     }
  47. }
  48. struct Zespolone* suma_wsk(struct Zespolone a,struct Zespolone b)
  49. {
  50.     struct Zespolone c;
  51.     c.re += b.re;
  52.     c.im += b.im;
  53.     struct Zespolone* wsk;
  54.     wsk=&c;
  55.     return wsk;
  56. }
  57. struct Zespolone* roznica_wsk(struct Zespolone a,struct Zespolone b)
  58. {
  59.     c.re -= b.re;
  60.     c.im -= b.im;
  61.     Zespolone* wsk;
  62.     wsk=&c;
  63.     return wsk;
  64. }
  65. struct Zespolone* iloczyn_wsk(struct Zespolone a,struct Zespolone b)
  66. {
  67.     struct Zespolone c;
  68.     c.re = a.re*b.re - a.im*b.im;
  69.     c.im = a.re*b.im + a.im*b.re;
  70.     struct Zespolone* wsk;
  71.     wsk=&c;
  72.     return wsk;
  73. }
  74. struct Zespolone* iloraz_wsk(struct Zespolone a,struct Zespolone b)
  75. {
  76.     struct Zespolone c;wk
  77.     if (b.re == 0 && b.im == 0) printf("ERROR! Division by zero.\n");
  78.     else
  79.     {
  80.         c.re = (a.re*b.re + a.im*b.im)/(b.re*b.re + b.im*b.im);
  81.         c.im = (a.im*b.re - a.re*b.im)/(b.re*b.re + b.im*b.im);
  82.     }
  83.     struct Zespolone* wsk;
  84.     wsk=&c;
  85.     return wsk;
  86. }
Add Comment
Please, Sign In to add comment