📜  带有示例的C++中的norm()函数

📅  最后修改于: 2021-05-30 08:41:25             🧑  作者: Mango

norm()函数在复杂头文件中定义。此函数用于返回复数z的平方大小。

句法:

template T norm (const complex& z);

范围:

  • z:代表给定的复数。

返回值:返回复数的平方大小。

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

范例1:-

// C++ program to demonstrate
// example of norm() function.
   
#include 
using namespace std;
   
// driver function
int main ()
{
  // initializing the complex: (5.0+12.0i)
  complex complexnumber (5.0, 12.0);
   
  // use of norm()function
  cout << "The norm of " << complexnumber << " is ";
  cout << norm(complexnumber) << endl;
   
  return 0;
}
输出:
The norm of (5,12) is 169

示例2:

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