用结构体实现复数运算的乘、除法
#include<stdio.h>typedef struct{double a;double b;}Complex;void InitC(Complex &C){scanf("%lf%lf",&C.a,&C.b);}Complex mulC(Complex C1,Complex C2){Complex C3;C3.a=C1.a*C2.a-C1.b*C2.b;C3.b=C1.a*C2.b+C2.a*C1.b;return C3;}Complex divC(Complex C1,Complex C2){Complex C4;C4.a=1.0*(C1.a*C2.a+C1.b*C2.b)/(C2.a*C2.a+C2.b*C2.b);C4.b=1.0*(C1.b*C2.a-C1.a*C2.b)/(C2.a*C2.a+C2.b*C2.b);return C4;}int main(){Complex C1,C2,C3,C4;printf("用结构体实现复数运算的乘、除法n");InitC(C1);InitC(C2);C3=mulC(C1,C2);C4=divC(C1,C2);if(C3.b<0)printf("n乘法:%.2f%.2fi",C3.a,C3.b);else{if(C3.b>0)printf("n乘法:%.2f+%.2fi",C3.a,C3.b);elseprintf("n乘法:%.2f",C3.a);}if(C4.b<0)printf("n除法:%.2f%.2fi",C4.a,C4.b);else {if(C4.b>0)printf("n除法:%.2f+%.2fi",C4.a,C4.b);elseprintf("n除法:%.2f",C4.a);}return 0;}