imag()函数在复杂头文件中定义。 imag()函数用于查找复数的虚部。
用法:
template<class T> T imag(const complex<T>& z);
参数:此方法采用强制性参数z:,它表示给定的复数。
返回:它返回复数的虚部。
以下示例程序旨在说明上述函数:-
示例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;
}
输出:
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 <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;
}
输出:
Complex Number = (2,2) Imag part of the complex number is =2
相关用法
- C++ div()用法及代码示例
- C++ fma()用法及代码示例
- C++ log()用法及代码示例
- C++ regex_iterator()用法及代码示例
- C++ map key_comp()用法及代码示例
- C++ real()用法及代码示例
- C++ valarray log()用法及代码示例
- C++ valarray pow()用法及代码示例
- C++ valarray tan()用法及代码示例
- C++ valarray cos()用法及代码示例
注:本文由纯净天空筛选整理自bansal_rtk_大神的英文原创作品 imag() function in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。