The area of a circle means the total area which is enclosed by the circle shape. The circumference or perimeter of a circle is the total length of the curve of the circle.
To find the area of a circle first, we have to know the radius of the circle and use the formula
Area = pi r2
To find the circumference or perimeter of a circle, we use the formula
Circumference = 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. The circumference or the perimeter will be
2 * π * 7 which will be 43.982.
In this PHP program, we are using the built-in functions
pi()for the pi(3.14)
pwo()to find the power of the value
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
Area = pi() * pow(radius, 2)
To find the circumference or perimeter we have to use the formula
circumference or Perimeter = 2 * pi() * radius
STEP 1: Accept the radius from the user and assign it to a variable radius
STEP 2: Calculate the area using formula 'pi() * pow(radius, 2)' and assign it to the variable area
STEP 3: Calculate the circumference using formula '2 * pi() * radius' and add that value to variable circumference
STEP 4: Print the values of the variable 'area' and 'circumference' as the area and circumference of the circle
<?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"); ?>
Enter the radius: 15 Area of circle is 706.858 Circumference of the circle is 94.248