PHP Program to find the Area and Circumference of the circle

Area and Circumference of the circle

There are mathematical formulas to find the area and circumference of the circle. To find the area of a circle first we have to get the radius of the circle and use the formula πpi rand to find the circumference we use the formula 2&pi r. For example, if the radius of the circle is 7 then the area of the circle will be π * 72 which will be 153.938 and circumference will be 2 * π * 7 which will be 43.982. 

How to find the area and circumference using PHP

In PHP there are many ways to find the area and circumference of the circle in this program we are using the built-in functions pi() for the pi(3.14) value and pwo() to find the power of the value and we are also using the round() to limit the number of digits after the decimal point. First, we have to read the radius from the user and assign it to a variable, and to find the area we have to use the formula pi() * pow(radius, 2) and to find the circumference we have to use the formula 2 * pi() * radius.

ALGORITHM 

Step 1: Accept the radius from the user and assign it to a variable radius

Step 2: Compute the operation to find the area 'pi() * pow(radius, 2)' and assign the value to the variable area

Step 3: Compute the operation to find the circumference '2 * pi() * radius' and assign the value to the variable circumference

Step 4: Print the values of the variable area and circumference as the area and circumference of the circle

PHP Source Code

                                          <?php
$radius = readline("Enter the radius: ");
$area = pi() * pow($radius, 2);      // pow() is used to find the power
$area = round($area, 3);            // round() is used to limit the number of digit after the decimal
$circumference = 2 * pi() * $radius;
$circumference = round($circumference, 3);
echo (" Area of circle is $area \n Circumference of the circle is $circumference");
?>
                                      

OUTPUT

Enter the radius: 15
Area of circle is 706.858
Circumference of the circle is 94.248