answersLogoWhite

0


Best Answer

typedef struct complex {

double real, imag;

} complex;

...

complex x, y, z;

...

/* add */

z.real = x.real + y.real;

z.imag = x.imag + y.imag;

/* sub */

z.real = x.real - y.real;

z.imag = x.imag - y.imag;

/* mul */

z.real = x.real*y.real - x.imag*y.imag;

z.imag =x.imag*y.real + x.real*y.imag;

/* div */

double d = y.real*y.real + y.imag*y.imag;

z.real = (x.real*y.real + x.imag*y.imag)/d;

z.imag = (x.imag*y.real - x.real*y.imag)/d;

User Avatar

Wiki User

βˆ™ 14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

βˆ™ 11y ago

#include<iostream>

#include<complex>

int main()

{

std::complex<double> a(1,0);

std::complex<double> b(3,1);

std::complex<double> c = a + b;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to calculate sum of two complex number in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp