complex - STL C++

imag()

Declaration

X imag(const complex<X>& kqrZ);

Description

This is the friend function imag() for complex numbers. It returns the imaginary part of the complex number kqrZ. The formula for the imaginary part of a complex number z = x + iy, for real numbers x and y is

imag(z) = y.

Header Include

#include <complex>

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create a complex number and get its imaginary part
	complex<double> qZ(2.0, 4.0);
	cout << "Complex Number : "<< qZ << endl;
	cout << "The imaginary part is "<< imag(qZ) << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

imag() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.