programming-examples/php/Basics/PHP program to compute and return the square root of a given number..php
2019-11-18 14:44:36 +01:00

15 lines
198 B
PHP

<?php
function my_sqrt($n)
{
$x = $n;
$y = 1;
while($x > $y)
{
$x = ($x + $y)/2;
$y = $n/$x;
}
return $x;
}
print_r(my_sqrt(16)."\n");
print_r(my_sqrt(14)."\n");
?>