#include#include int main() { std::complex c1(1.0, 2.0); // create complex number with real part 1.0 and imaginary part 2.0 std::complex c2(3.0, 4.0); // create another complex number std::cout << "c1 + c2 = " << c1 + c2 << std::endl; // add two complex numbers std::cout << "c1 * c2 = " << c1 * c2 << std::endl; // multiply two complex numbers return 0; }
#includeIn this example, we create a `std::complex#include int main() { std::complex c(2.0, 3.0); double r = std::real(c); // get real part of c (2.0) double i = std::imag(c); // get imaginary part of c (3.0) std::cout << "real part of c: " << r << std::endl; std::cout << "imaginary part of c: " << i << std::endl; return 0; }