numeros complejos o imaginarios

hola como estan necesito ayuda para poder usar una funcion que trabaje con numeros imaginarios.
para que el codigo me reciba numeros maginarios o raices negativas y no se rompa el codigo.
por favor help..
Last edited on
Something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

struct Complex {
	double real;
	double imag;

	Complex(double = 0.0, double = 0.0);

	static Complex sqrt(const Complex &n); //define
};

Complex::Complex(double r, double i) {
	real = r;
	imag = i;
}

const std::ostream& operator<<(const std::ostream &out, const Complex &n) {
	out << n.real << '+' << n.imag << 'i';
	return out;
}

Complex operator*(const Complex &a, const Complex &b); //define
Complex operator+(const Complex &a, const Complex &b) { return Complex( a.real + b.real, a.imag + b.imag ); }
Complex operator-(const Complex &n) { return -1 * n; }
Complex operator-(const Complex &a, const Complex &b) { return a + -b; }
//ect... 


http://translate.google.com
Last edited on
The complex class (#include <complex> ) handles complex numbers for you. Negative roots aren't a problem. You'll just have to watch out for the things the documentation says will raise exceptions (like a base of zero and a negative exponent).

How is it you get the imaginary numbers?
What is the function supposed to do?
Is this homework?
Topic archived. No new replies allowed.