![]() |
VOOZH | about |
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*iInput: A = 4, B = 0
Output:
The Square roots are:
2
-2
Approach: The given problem can be solved based on the following observations:
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:
The Square roots are: 0.707107+0.707107*i -0.707107-0.707107*i
Time Complexity: O(1)
Auxiliary Space: O(1)