PHP Program to find the square root of the number using sqrt()


April 27, 2022, Learn eTutorial
1217

How to find the square root of the number using sqrt() in PHP?

In this program, we are using the built-in function sqrt() to find the square root of the entered number. For that, we first have to accept the number from the user and assign it to the variable num. And then find the square root of the value in the variable num by using the built-in function sqrt() with argument num and assign the result into the variable sr after that print the value of the variable sr as the square root of the entered number.

Syntax


sqrt(number);
 

ALGORITHM

Step 1: Accept the number from the user and assign it to the variable num

Step 2: Find the square root of the value in the variable num by using the built-in function sqrt() with argument num and assign the result into the variable sr

Step 3: Print the value of the variable sr as the square root of the entered number

PHP Source Code

                                          <?php
$num = readline("Enter the number: ");
$sr = sqrt($num);
echo "The square root of the number $num is $sr";
?>
                                      

OUTPUT

Enter the number: 25
The square root of the number 25 is 5