answersLogoWhite

0

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

Still curious? Ask our experts.

Chat with our AI personalities

BeauBeau
You're doing better than you think!
Chat with Beau
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers

#include<iostream>

#include<complex>

int main()

{

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

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

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

}

User Avatar

Wiki User

11y ago
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