C++ examples for Data Type:complex
Demonstrate the complex class.
#include <iostream> #include <complex> using namespace std; int main()/*from ww w . ja v a2 s .c om*/ { complex<double> cmpx1(1, 0); complex<double> cmpx2(1, 1); cout << "cmpx1: " << cmpx1 << endl << "cmpx2: " << cmpx2 << endl; // Add two complex numbers. cout << "cmpx1 + cmpx2: " << cmpx1 + cmpx2 << endl; // Multiply two complex numbers. cout << "cmpx1 * cmpx2: " << cmpx1 * cmpx2 << endl; // Add a scalar to a complex number. cmpx1 += 2.0; cout << "cmpx1 += 2.0: " << cmpx1 << endl; // Find the sin of cmpx2. cout << "sin(cmpx2): " << sin(cmpx2) << endl; return 0; }