#include #include typedef struct complex { float i;//虚部 float r;// 实部 }D; D init(); void sum(D a,D b);//求和 void jian(D a,D b);//减 void cheng(D a,D b);//乘 void chu(D a,D b);//除 float getr(D a);//取得实部 float geti(D b);//取得虚部 void main() { D a,b; float x,y; a=init(); b=init(); sum(a,b); jian(a,b); cheng(a,b); chu(a,b); x=getr(a); y=geti(a); } D init() { float x,y; D l; printf("请输入实部虚部\n"); scanf("%f%f",&x,&y); l.i=y; l.r=x; return l; } void sum(D a,D b) { D c; c.i=a.i+b.i; c.r=a.r+b.r; printf("c=a+b\n"); printf("c=%0.1f+%0.1fi\n",c.r,c.i); } void jian(D a,D b) { D c; c.i=a.i-b.i; c.r=a.r-b.r; printf("d=a-b\n"); printf("d=%0.1f+%0.1fi\n",c.r,c.i); } void cheng(D a,D b) { D c; c.i=b.r*a.i+b.i*a.r; c.r=a.r*b.r-a.i*b.i; printf("e=a*b\n"); printf("e=%0.1f+%0.1fi\n",c.r,c.i); } void chu(D a,D b) { D c; c.i=(a.i*b.r-a.r*b.i)/(b.i*b.i+b.r*b.r); c.r=(a.r*b.r+b.i*b.i)/(b.i*b.i+b.r*b.r); printf("f=a/b\n"); printf("f=%f+%fi\n",c.r,c.i); } float getr(D a) { printf("要找的实部=%0.1f\n",a.r); return(a.r); } float geti(D a) { printf("要找的虚部=%0.1f\n”,a.i) return(a.i); } 本文来源:https://www.wddqw.com/doc/1b816509de36a32d7375a417866fb84ae45cc336.html