
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements