带有示例的C ++中的norm()函数
在本文中,我们将讨论norm()C++STL中函数的工作,语法和示例。
什么norm()啊
norm()函数是C++STL中的内置函数,在<complex>头文件中定义。norm()函数用于获取复数的范数。
复数的范数是数字的平方大小。因此,用简单的话来说,函数会找到复数的平方大小,包括虚数和实数。
语法
double norm(ArithmeticType num);
参数
该函数接受以下参数-
num-我们要处理的复杂值。
返回值
此函数返回范数num。
示例
输入值
complex<double> comp_num(6.9, 2.6); norm(comp_num);
输出结果
规范的值 (6.9,2.6) is 54.37
示例
#include <bits/stdc++.h>
using namespace std;
int main (){
complex<double> comp_num(6.9, 2.6);
cout<<"规范的值 " << comp_num<< " is ";
cout << norm(comp_num) << endl;
return 0;
}输出结果
规范的值 (6.9,2.6) is 54.37
示例
#include <bits/stdc++.h>
using namespace std;
int main (){
complex<double> comp_num(2.4, 1.9);
cout<<"规范的值 " << comp_num<< " is ";
cout << norm(comp_num) << endl;
return 0;
}示例
规范的值 (2.4,1.9) is 9.37