1 #include <cstdio> 2 #include <cmath> 3 #define EPS 1e-1 4 5 void print1(double a,double b,double c,double d,char op) 6 { 7 printf("(%.1f%+.1fi) %c (%.1f%+.1fi) = ",a,b,op,c,d); 8 } 9 10 void print2(double a,double b) 11 { 12 if(fabs(a)<=EPS && fabs(b)<=EPS) 13 printf("0.0\n"); 14 else if(fabs(b)<=EPS) 15 printf("%.1f\n",a); 16 else if(fabs(a)<=EPS) 17 printf("%.1fi\n",b); 18 else 19 printf("%.1f%+.1fi\n",a,b); 20 } 21 22 int main() 23 { 24 double a,b,c,d; 25 scanf("%lf%lf%lf%lf",&a,&b,&c,&d); 26 print1(a,b,c,d,‘+‘); 27 print2(a+c,b+d); 28 print1(a,b,c,d,‘-‘); 29 print2(a-c,b-d); 30 print1(a,b,c,d,‘*‘); 31 print2(a*c-b*d,a*d+b*c); 32 print1(a,b,c,d,‘/‘); 33 print2((a*c+b*d)/(c*c+d*d),(b*c-a*d)/(c*c+d*d)); 34 return 0; 35 }
原文:http://www.cnblogs.com/fcp1024/p/4296340.html