imag() function in C++
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:-
// C++ program to demonstrate // example of imag() function. #include <bits/stdC++.h> using namespace std; // Driver function int main() { // defines the complex number: (20.3 + 4.9i) complex<double> imagpart(20.3, 4.9); // print the complex number cout << "Complex Number = " << imagpart << endl; // prints the imag part using the imag function cout << "Imag part of the complex number is =" << imag(imagpart) << endl; return 0; } |
chevron_right
filter_none
Output:
Complex Number = (20.3,4.9) Imag part of the complex number is =4.9
Example 2:-
// C++ program to demonstrate // example of imag() function. #include <bits/stdC++.h> using namespace std; // driver function int main() { // defines the complex number: (2 + 2i) complex<double> imagpart(2, 2); // print the complex number cout << "Complex Number = " << imagpart << endl; // prints the imag part using the imag function cout << "Imag part of the complex number is =" << imag(imagpart) << endl; return 0; } |
chevron_right
filter_none
Output:
Complex Number = (2,2) Imag part of the complex number is =2
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- log() function in C++
- exp() function C++
- div() function in C++
- fma() function in C++
- strtoumax() function in C++
- strtoimax() function in C++
- wctype() function in C/C++
- mbsrtowcs() function in C/C++
- bit_and function in C++
- iswctype() function in C/C++
- mbsinit() Function in C/C++
- wcspbrk() function in C/C++
- mbrlen() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



