C++ 中的 norm() 函式及其示例
在本文中,我們將討論 C++ STL 中 norm() 函式的工作原理、語法以及示例。
什麼是 norm()?
norm() 函式是 C++ STL 中的一個內建函式,它定義在 <complex> 標頭檔案中。norm() 函式用於獲取複數的範數。
複數的範數是一個數的平方幅度。因此,簡單來說,該函式會查詢一個複數(包括其虛數和實數)的平方幅度。
語法
double norm(ArithmeticType num);
引數
該函式接受以下引數:
- num ― 我們要對其進行處理的複數值。
返回值
此函式返回 num 的範數值。
示例
輸入
complex<double> comp_num(6.9, 2.6); norm(comp_num);
輸出
The value of norm of (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<<"The value of norm of " << comp_num<< " is ";
cout << norm(comp_num) << endl;
return 0;
}輸出
The value of norm of (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<<"The value of norm of " << comp_num<< " is ";
cout << norm(comp_num) << endl;
return 0;
}示例
The value of norm of (2.4,1.9) is 9.37
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP