imag()函数在复杂的头文件中定义。 imag()函数用于查找复数的虚部。
句法:
template T
imag(const complex& z);
参数:此方法采用必填参数z:,它表示给定的复数。
返回值:返回复数的虚部。
下面的程序说明了上述函数:-
范例1:-
// C++ program to demonstrate
// example of imag() function.
#include
using namespace std;
// Driver function
int main()
{
// defines the complex number: (20.3 + 4.9i)
complex 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;
}
输出:
Complex Number = (20.3,4.9)
Imag part of the complex number is =4.9
示例2:
// C++ program to demonstrate
// example of imag() function.
#include
using namespace std;
// driver function
int main()
{
// defines the complex number: (2 + 2i)
complex 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;
}
输出:
Complex Number = (2,2)
Imag part of the complex number is =2
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。