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