Google News
logo
PHP Program to Find the square root of a number
In PHP, you can find the square root of a number using the `sqrt()` function. Here's an example :
Program :
<?php
$number = 16;
$sqrt = sqrt($number);

echo "The square root of $number is $sqrt\n";
?>
Output :
The square root of 16 is 4
In this example, the variable `$number` is defined with the value `16`. The `sqrt()` function is called with `$number` as an argument to find the square root of `16`, and the result is stored in the variable `$sqrt`.

The value of `$sqrt` is then output using `echo`.

Note that the `sqrt()` function returns a float value, even if the input is a perfect square. If you want to check if a number is a perfect square, you can use the `is_int(sqrt($number))` function, which will return `true` if the square root of the number is an integer.