sqrt()函数,用于C ++中的复数
给定任务是找到sqrt()复数的函数的作用。基本上,sqrt()是复杂头文件中存在的函数。此函数用于计算复数的平方根。
语法
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)