how to program complex numbers

hello my friends :
i thought a lot of how i program the general combined number
in the form a+i*b
while i = sqrt(-1)
the problem to be in the compiler don`t take the value sqrt (-1)
as it However i*i also cant display
i thanks very much if you help me for this matter

buzzy
thank you for your interesting in my topic
my friend i need a source code explain using complex numbers
and in the time seem to be ease to understanding
thanks a lot
my friend i need a source code explain using complex numbers
and in the time seem to be easy to understanding
thanks a lot
Last edited on
Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <complex>

using namespace std;

typedef complex<double> comp; // to type less on declarations

int main()
{
    const comp i = sqrt ( comp(-1) ); // force the call to the overload of sqrt found in <complex>
    comp x = 1.0 + i * 2.0;
    comp y ( 3, 4 ); // 3 + 4*i
    cout << x+y << endl // default format: (real,imag )
         << x.real() << " + i*" << x.imag() << endl; // custom format: real +  i*imag
}

Topic archived. No new replies allowed.