I need to calculate the square root of a number to at least one decimal place without using the built-in PHP mathematical functions. In other words, we can only use multiplication, division, addition and subtraction.
Example: calculate_square_root(56)
would result in: 7.4
Note: I need a recursion based code for above problem
Please help anyone to sort out the problem and thanks in advance.
Simple.....
function calculate_square_root($number) {
return parseInt($number^0.5*10)/10;
}
edit sorry: here you go without built in...
edit2 as pointed out in the comments below, the caret ^
is not for power/exponent, but is for XOR. So This answer is WRONG.