C++ 中關於複數的 sqrt () 函式
這裡有一個任務,即找出如何對複數使用 sqrt() 函式。基本上,sqrt() 是 complex 標標頭檔案中存在的一個函式。此函式用於計算複數的平方根。
語法
template<class t> complex<t> Sqrt(const complex<t>& x);
引數
x − 這個 x 引數表示複數。
返回值
此函式返回複數的平方根。
輸入 − Sqrt(3,8i)
輸出 − (2.4024,1.6649)
輸入 Sqrt(7,1i)
輸出 − (2.6524,0.1885)
例項
#include<iostream.h>
#include<complex.h>
Using namespace std;
int main( ){
/ / Defining of complex Number
Complex<double> x(4,9);
Cout<< “ The square root of “ << x << “ = “ << sqrt(x) << endl;
Return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
The square root of (4,9) = (2.631,1.710)
例項
#include<iostream.h>
#include<complex.h>
Using namespace std;
int main( ){
/ / defining the complex Number
Complex<double> x(2, 6);
Cout<< “ The square root of “ << x << “ = “ << sqrt(x) << endl;
return 0;
}輸出
如果我們執行以上程式碼,它將生成以下輸出
The square root of (2,6) = (2.0401,1.4704)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP