Computer Science, asked by angel3748, 1 month ago

4. Write a program to accept two variables. One variable for choice and other
variable for accepting any number. If choice is 1 then print the cube root and if
choice is 2 then print it's Square root.

Answers

Answered by avtars1375
0

Answer:

Using Binary Search: This approach is used to find the square root of the given number N with precision upto 5 decimal places.

The square root of number N lies in range 0 ≤ squareRoot ≤ N. Initialize start = 0 and end = number.

Compare the square of the mid integer with the given number. If it is equal to the number, then we found our integral part, else look for the same in the left or right side of mid depending upon the condition.

After finding an integral part, we will find the fractional part.

Initialize the increment variable by 0.1 and iteratively calculate the fractional part upto 5 decimal places.

For each iteration, change increment to 1/10th of its previous value.

Finally, return the answer computed.

Similar questions