Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. struct complex
  6. {
  7. double re,im;
  8.  
  9.  
  10.  
  11. };
  12.  
  13. complex add(complex z, complex w)
  14. {
  15. complex t;
  16. t.re = z.re+w.re;
  17. t.im=z.im+w.im;
  18. return t;
  19. }
  20. //makrodefinicja
  21. #define sqr(x) ((x)*(x))
  22.  
  23. double module (complex z)
  24. {
  25. return sqrt(sqr(z.re)+sqr(z.im));
  26. }
  27.  
  28. void print (complex z)
  29. {
  30. cout<<"("<<z.re<<","<<z.im<<")"<<endl;
  31.  
  32.  
  33. }
  34.  
  35. main()
  36. {
  37. complex z, w, t;
  38. z.re=1; z.im=-3;
  39. w.re=-2; w.im=2.5;
  40. t=add(z,w);
  41. print(t);
  42. cout<<module(t)<<endl;
  43.  
  44. system("pause");
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement