Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct complex
  4. {
  5. float real;
  6. float imag;
  7. };
  8.  
  9. int main()
  10. {
  11. struct complex cplx = {6, 5};
  12. print_cplx(cplx);
  13. return 0;
  14. }
  15.  
  16. float cplx_real(struct complex cplx)
  17. {
  18. return cplx.real;
  19. }
  20.  
  21. float cplx_imag(struct complex cplx)
  22. {
  23. return cplx.imag;
  24. }
  25.  
  26. struct complex cplx_conj(struct complex cplx)
  27. {
  28. cplx.imag = -cplx.imag;
  29. return cplx;
  30. }
  31.  
  32. void print_cplx(struct complex cplx)
  33. {
  34. printf("%.4f + %.4fi", cplx.real, cplx.imag);
  35. }
  36.  
  37. struct complex cplx_add(const struct complex cplx1, const struct complex cplx2)
  38. {
  39. struct complex cplx = {cplx1.real+cplx2.real, cplx1.imag+cplx2.imag};
  40. return cplx;
  41. }
  42.  
  43. struct complex cplx_sub(const struct complex cplx1, const struct complex cplx2)
  44. {
  45. struct complex cplx = {cplx1.real-cplx2.real, cplx1.imag-cplx2.imag};
  46. return cplx;
  47. }
  48.  
  49. struct complex cplx_nul(const struct complex cplx1, const struct complex cplx2)
  50. {
  51. struct complex cplx = {cplx1.real*cplx2.real, cplx1.imag*cplx2.imag};
  52. return cplx;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement