时间:2021-06-05 08:59:41 | 栏目:C代码 | 点击:次
废话不多说,直接上代码
typedef struct
{
double real;
double imag;
} complex;
//复数乘法
complex X_complex(complex a, complex b)
{
complex temp;
temp.real = a.real * b.real - a.imag * b.imag;
temp.imag = b.imag * a.real + a.imag * b.real;
return temp;
}
int main(int argc, char *argv[])
{
complex a,b,c;
a.real = 2;
a.imag = 3;
b.real = 4;
b.imag = 5;
c = X_complex(a,b);//结构体可以作为返回值,然后赋值给另一个相同结构体的变量
cout<<c.real<<","<<c.imag<<endl;
return 0;
}