Write a PHP program to compute and return the square root of a given number.
Input : 16
<?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"); ?>
Sample Output:
4 3.7416573867739
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer