Implementation code for struct assignment in complex multiplication
- 2020-04-02 01:45:26
- OfStack
Without further ado, go straight to the code
#include <iostream>
using namespace std;
typedef struct
{
double real;
double imag;
} complex;
//Complex multiplication
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);//A structure can be used as a return value and then assigned to another variable of the same structure
cout<<c.real<<","<<c.imag<<endl;
return 0;
}