imag() function in C++
Last Updated :
08 Oct, 2018
The imag() function is defined in the complex header file. The imag() function is used to find the imaginary part of the complex number.
Syntax:
template<class T> T
imag(const complex<T>& z);
Parameter: This method takes a mandatory parameter z: which represents the given complex number.
Return: It returns the imaginary part of the complex number.
Below programs illustrate the above function:-
Example 1:-
#include <bits/stdC++.h>
using namespace std;
int main()
{
complex< double > imagpart(20.3, 4.9);
cout << "Complex Number = "
<< imagpart << endl;
cout << "Imag part of the complex number is ="
<< imag(imagpart) << endl;
return 0;
}
|
Output:
Complex Number = (20.3,4.9)
Imag part of the complex number is =4.9
Example 2:-
#include <bits/stdC++.h>
using namespace std;
int main()
{
complex< double > imagpart(2, 2);
cout << "Complex Number = "
<< imagpart << endl;
cout << "Imag part of the complex number is ="
<< imag(imagpart) << endl;
return 0;
}
|
Output:
Complex Number = (2,2)
Imag part of the complex number is =2
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...