满意答案
aiwenyou
2015.06.18
采纳率:46% 等级:9
已帮助:762人
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#include typedef struct { float r; float i;}Complex; Complex readComlexNumber() { Complex n; printf("Input real part:"); scanf("%f", &n.r); printf("Input imaginary part:"); scanf("%f", &n.i); return n;} Complex sumComplex(Complex a, Complex b) { Complex c; c.r = a.r + b.r; c.i = a.i + b.i; return c;} Complex differeneComplex(Complex a, Complex b) { Complex c; c.r = a.r-b.r; c.i = a.i-b.i; return c;} Complex multiplyComplex(Complex a, Complex b) { Complex c; c.i = a.r * b.i + a.i*b.r; c.r = a.r * b.r - a.i*b.i; return c;} Complex divideComplex(Complex a, Complex b) { Complex c; c.r = (a.r*b.r+a.i*b.i)/(b.r*b.r+b.i*b.i); c.i = (a.i*b.r-a.r*b.i)/(b.r*b.r+b.i*b.i); return c;} void printComplex(Complex n) { printf("%.2f+%.2fi", n.r, n.i);} int main(){ Complex a, b, c; printf("Input Complex number a:\n"); a = readComlexNumber(); printf("Input Complex number b:\n"); b = readComlexNumber(); printf("The 2 Complex a & b is :\n"); printComplex(a); printf(" and "); printComplex(b); //sum c = sumComplex(a, b); printf("\n (a+b)="); printComplex(c); //diff c = differeneComplex(a, b); printf("\n (a-b)="); printComplex(c); //multiply c = multiplyComplex(a, b); printf("\n (a*b)="); printComplex(c); //divide c = divideComplex(a, b); printf("\n (a/b)="); printComplex(c); return 0;}
00分享举报