complex - STL C++

sqrt()

Declaration

complex<X> sqrt(const complex<X>& kqrZ);

Description

This is the friend function sqrt() for complex numbers. It returns the square root of the complex number kqrZ. The square root always lies in the right-half plane with an argument value in the interval (-pi/2, pi/2], since the branch cuts along the negative real axis.

Header Include

#include <complex>

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create a complex number and calculate its square root
	complex<double> qZ(2.0, 4.0);
	cout << "Complex Number : "<< qZ << endl;
	cout << "The square root is "<< sqrt(qZ) << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

sqrt() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.