I know I've asked a question like this before. It was about Python. But in C ++, how do you insert a complex number?
I know I've asked a question like this before. It was about Python. But in C ++, how do you insert a complex number?
In c ++ you have the complex type. It can be used as follows:
// 1 + 2i
std::complex<double> c(1, 2);
The constructor receives two parameters:
In C (it's not in the question, but it's in a tag) I do it
#include <complex.h>
#include <stdio.h>
int main(void) {
complex double x, y, z;
x = 3.14159 - 2*_Complex_I;
y = 2.71828182 - _Complex_I;
z = x - 2*y; printf("x - 2y = %f%+fi\n", creal(z), cimag(z));
}
You can see the code working on ideone .
(In C ++ I have no idea)