VOOZH about

URL: https://www.geeksforgeeks.org/dsa/square-root-of-two-complex-numbers/

⇱ Square root of two Complex Numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Square root of two Complex Numbers

Last Updated : 23 Jul, 2025

Given two positive integers A and B representing the complex number Z in the form of Z = A + i * B, the task is to find the square root of the given complex number.

Examples:

Input: A = 0, B =1
Output:
The Square roots are: 
0.707107 + 0.707107*i
-0.707107 - 0.707107*i

Input: A = 4, B = 0
Output:
The Square roots are: 
2
-2

Approach: The given problem can be solved based on the following observations:

  • It is known that the square root of a complex number is also a complex number.
  • Then considering the square root of the complex number equal to X + i*Y, the value of (A + i*B) can be expressed as:
    • A + i * B = (X + i * Y) * (X + i * Y)
    • A + i * B = X2 - Y2+ 2 * i * X * Y
  • Equating the value of real and complex parts individually:

From the above observations, calculate the value of X and Y using the above formula and print the value (X + i*Y) as the resultant square root value of the given complex number.

Below is the implementation of the above approach:


Output: 
The Square roots are: 
0.707107+0.707107*i
-0.707107-0.707107*i

 

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment
Article Tags: