📜  C ++中的real()函数

📅  最后修改于: 2021-05-31 23:48:54             🧑  作者: Mango

real()函数在复杂的头文件中定义。 real()函数用于查找复数的实部。

句法:

template T 
    real(const complex& z);

参数:此方法采用必填参数z:,它表示给定的复数。

返回值:返回指定复数的实数部分

下面的程序说明了上述函数:-

范例1:-

// C++ program to demonstrate
// example of real() function.
  
#include 
using namespace std;
  
// driver function
int main()
{
    // defines the complex number: (20.3 + 4.9i)
    complex realpart(20.3, 4.9);
  
    // print the complex number
    cout << "Complex Number = "
         << realpart << endl;
  
    // prints the real part using the real function
    cout << "Real part of the complex number is ="
         << real(realpart) << endl;
  
    return 0;
}
输出:
Complex Number = (20.3, 4.9)
Real part of the complex number is =20.3

示例2:

// C++ program to demonstrate
// example of real() function.
  
#include 
using namespace std;
  
// driver function
int main()
{
    // defines the complex number: (2 + 2i)
    complex realpart(2, 2);
  
    // print the complex number
    cout << "Complex Number = "
         << realpart << endl;
  
    // prints the real part using the real function
    cout << "Real part of the complex number is ="
         << real(realpart) << endl;
  
    return 0;
}
输出:
Complex Number = (2, 2)
Real part of the complex number is =2
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”