Advertisement
Guest User

complex_msp430

a guest
Oct 8th, 2019
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <complex.h>
  2. #include <cross_studio_io.h>
  3.  
  4. void main(void)
  5. {
  6.   double complex z1 = 1.0 + 3.0 * I;
  7.   double complex z2 = 1.0 - 4.0 * I;
  8.  
  9.   debug_printf("Working with complex numbers:\n\v");
  10.  
  11.   debug_printf("Starting values: Z1 = %.2f + %.2fi\tZ2 = %.2f %+.2fi\n", creal(z1), cimag(z1), creal(z2), cimag(z2));
  12.  
  13.   double complex sum = z1 + z2;
  14.   debug_printf("The sum: Z1 + Z2 = %.2f %+.2fi\n", creal(sum), cimag(sum));
  15.  
  16.   double complex difference = z1 - z2;
  17.   debug_printf("The difference: Z1 - Z2 = %.2f %+.2fi\n", creal(difference), cimag(difference));
  18.  
  19.   double complex product = z1 * z2;
  20.   debug_printf("The product: Z1 x Z2 = %.2f %+.2fi\n", creal(product), cimag(product));
  21.  
  22.   double complex quotient = z1 / z2;
  23.   debug_printf("The quotient: Z1 / Z2 = %.2f %+.2fi\n", creal(quotient), cimag(quotient));
  24.  
  25.   double complex conjugate = conj(z1);
  26.   debug_printf("The conjugate of Z1 = %.2f %+.2fi\n", creal(conjugate), cimag(conjugate));
  27.  
  28.   debug_exit(0);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement