// A short example to show how to declare a complex number in C++. #include #include using namespace std; int main( ) { double_complex x; // Set x equal to the square root of -1. Notice that we cannot simply // write sqrt(-1) because that would use the ordinary sqrt function. // The notaton (double_complex) -1 is used to convert -1 to // a double_complex data type, and then the complex version of sqrt // will be used. x = sqrt( (double_complex) -1); // Complex numbers can be printed. This one will print as (0,-1), // which means that its real part is zero and its imaginary part is -1. cout << x << endl; return 0; // Tell the operating system that the program succeeded. }