programming-examples/php/Basics/PHP program to compute and return the square root of a given number..php

15 lines
198 B
PHP
Raw Normal View History

2019-11-18 14:44:36 +01:00
<?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");
?>