C Output Question gate 2014


#1

Consider the following function

double f(double x){
if( fabs(x*x - 3) < 0.01)
return x;
else
return f(x/2 + 1.5/x);
}

Give a value q (to 2 decimals) such that f(q) will return q:_____.


#2

example q = 2.44

f(2.44) = (2.44*2.44 -3) < 0.01 … this is false
so f(2.44/2 + 1.5/2.44) will execute … f(1.83) wil be calculated
Hence value must be 0.01 which will be the case when 0.001 type condition will come, hence
0.000000 always


#3

fabs(x*x - 3)<0.01
x*x - 3 < 0.01 and -(x*x-3)<0.01
x*x<3.01 and x*x > 2.99
x < 1.7349351 and x > 1.7291616
so x = 1.73