fork download
  1. #include<stdio.h>
  2. struct complex
  3. {
  4. double real; //実数部
  5. double imaginary; //虚数部
  6. };
  7.  
  8. struct complex complex_add(struct complex func_a, struct complex func_b){
  9. struct complex func_c;
  10. func_c.real = func_a.real + func_b.real;
  11. func_c.imaginary = func_a.imaginary + func_b.imaginary;
  12. return func_c;
  13. }
  14.  
  15. void print_complex(char message[],struct complex a){
  16. printf("%s = %3lf + %3lfi\n",message,a.real,a.imaginary);
  17. }
  18.  
  19. int main(){
  20.  
  21. struct complex a,b,c;
  22.  
  23. a.real = 10;
  24. a.imaginary = 5;
  25. b.real = 20;
  26. b.imaginary = 3;
  27.  
  28. c = complex_add(a,b);
  29.  
  30. print_complex("a",a);
  31. print_complex("b",b);
  32. print_complex("a + b",c);
  33.  
  34. return(0);
  35. }
  36.  
Success #stdin #stdout 0.02s 1720KB
stdin
Standard input is empty
stdout
a = 10.000000 + 5.000000i
b = 20.000000 + 3.000000i
a + b = 30.000000 + 8.000000i