fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. typedef struct NI {
  5. float real;
  6. float imag;
  7. }complexo;
  8.  
  9. void soma(complexo z, complexo w){
  10. complexo s;
  11. s.real=z.real+w.real;
  12. s.imag=z.imag+w.imag;
  13. printf("%f + %fi\n",s.real,s.imag);
  14. }
  15.  
  16. void produto(complexo z, complexo w){
  17. complexo m;
  18. m.real = z.real*w.real - z.imag*w.imag;
  19. m.imag = z.real*w.imag + z.imag*w.real;
  20. printf("%f + %fi\n",m.real,m.imag);
  21. }
  22.  
  23. int main(){
  24. complexo z,w;
  25. char op;
  26.  
  27. scanf("%f %f %c %f %f",&z.real, &z.imag, &op, &w.real, &w.imag);
  28.  
  29. if(op=='+'){
  30. soma(z, w);
  31. }
  32. if(op=='*'){
  33. produto(z, w);
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 4460KB
stdin
1 2 + 3 4
stdout
4.000000 + 6.000000i