分别输入2个复数的实部与虚部,用函数实现计算2个复数之和与之积。
若2个复数分别为:c1=x1+(y1)i, c2=x2+(y2)i,则:
c1+c2 = (x1+x2) + (y1+y2)i
c1*c2 = (x1*x2-y1*y2) + (x1*y2+x2*y1)i
输入格式:
输入在一行中给出4个实数,分别代表c1和c2的实部和虚部。
输出格式:
在两行中分别输出c1+c2和c1*c2的计算结果。
输入样例:
1 1 -2 3
输出样例:
addition of complex is -1.000000+4.000000i
product of complex is -5.000000+1.000000i
代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB
#include <stdio.h>
typedef struct {
double real;
double imag;
} Complex;
Complex addComplex(Complex c1, Complex c2) {
Complex result;
result.real = c1.real + c2.real;
result.imag = c1.imag + c2.imag;
return result;
}
Complex multiplyComplex(Complex c1, Complex c2) {
Complex result;