sqrt ( ) function for complex number in C++


Given is the task to find the working of sqrt() function for complex number. Basically the sqrt( ) is a function present in complex header file. This function is used to calculate the square root of complex number.

Syntax

template<class t> complex<t>
Sqrt(const complex<t>& x);

Parameter

x − This parameter x which represent the complex number.

Return Value

This function returns the square root of the complex number.

Input  − Sqrt(3,8i)

Output − (2.4024,1.6649)

Input Sqrt(7,1i)

Output − (2.6524,0.1885)

Example

#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;
}

Output

If we run the above code it will generate the following output

The square root of (4,9) = (2.631,1.710)

Example

#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;
}

Output

If we run the above code it will generate the following output

The square root of (2,6) = (2.0401,1.4704)

Updated on: 14-Aug-2020

345 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements