#include <stdio.h>
struct complex{
int real;
int imag;
};
struct complex multiply(struct complex x, struct complex y);
int main()
{
struct complex product, x, y;
scanf("%d%d%d%d", &x.real, &x.imag, &y.real, &y.imag);
product = multiply(x, y);
printf("(%d+%di) * (%d+%di) = %d + %di\n",
x.real, x.imag, y.real, y.imag, product.real, product.imag);
return 0;
}
struct complex multiply(struct complex x, struct complex y){
struct complex s;
s.real=x.real*y.real-x.imag*y.imag;
s.imag=x.real*y.imag+x.imag*y.real;
return s;
//这和调用函数很类似,只不过类型由最简单的int转变为结构体struct complex
//而multiply是这个函数的名字,用来承载结果的时候需要定义一个新的struct complex型的变量
//自己糊里糊涂犯错误直接用函数名计算了,导致编译错误
}
//也就是每出现此结构体类型的,就代表该变量具有结构体中的所有属性!!!