Consider the following function.
double f(double x){
if( abs(x*x - 3) < 0.01)
return x;
else
return f(x/2 + 1.5/x);
}
Give a value (to decimals) such that will return :_____.
View worked solution
Answer: 1.72 : 1.74
The given C function implements the Newton-Raphson method to find the square root of .
The base condition of the recursion is:
For to return directly without entering any further recursive steps, the base condition must be satisfied for . That is:
Solving this inequality:
Taking the positive square root:
Thus, the only value of rounded to decimal places that satisfies this condition is (or if considering negative roots).
The official GATE answer key accepts any value in the range to .
Free practice · Your answers on this page are not saved.
