# sqrt ( ) function for complex number in C++

C++Server Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

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 08:09:49