1
0

complex.c 860 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // complex.c
  2. #include <stdio.h>
  3. #include <complex.h>
  4. void show_cmlx(complex double cv);
  5. int main(void)
  6. {
  7. complex double v1 = 4.0 + 3.0*I;
  8. double re, im;
  9. complex double v2;
  10. complex double sum, conj1;
  11. printf("Enter the real part of a complex number: ");
  12. scanf("%lf", &re);
  13. printf("Enter the imaginary part of a complex number: ");
  14. scanf("%lf", &im);
  15. v2 = CMPLX(re, im);
  16. // v2 = re + im * I;
  17. show_cmlx(v1);
  18. putchar('\n');
  19. show_cmlx(v2);
  20. putchar('\n');
  21. sum = CMPLX(creal(v1)+creal(v2), (cimag(v1) + cimag(v2)));
  22. // sum = creal(v1)+creal(v2) +(cimag(v1)+ cimag(v2)) * I;
  23. conj1 =conj(v1);
  24. show_cmlx(sum);
  25. putchar('\n');
  26. show_cmlx(conj1);
  27. putchar('\n');
  28. return 0;
  29. }
  30. void show_cmlx(complex double cv)
  31. {
  32. printf("(%f, %fi)", creal(cv), cimag(cv));
  33. return;
  34. }