PHP
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
$number = 65;
$sqrt_result = round(sqrt($number),2);
echo "<br>The square root of $number is: $sqrt_result";
?>
<br><br>Or Without<br><br>
<?php
// Define a number to calculate the square root of
/* In the Babylonian method, the $precision variable is used to determine the accuracy of the square root approximation.*/
$number = 65;
// no sqrt function
function no_sqrt_func($number, $precision = 1e-6) {
$unknown = $number / 2;
while (abs($unknown * $unknown - $number) > $precision) {
$unknown = ($unknown + $number / $unknown) / 2;
}
return $unknown;
}
$square_root = no_sqrt_func($number);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run