![]() |
Given a Radius of Circle, the task is to find the Area and Perimeter of Circle in PHP. To find the area, use the formula π * r2, where r is the radius of the circle. To find the perimeter (circumference), use the formula 2 * π * r. There are two approaches to calculate the area and perimeter (circumference) of a circle using PHP: Table of Content Using Functions and Constants for PiThe area of a circle is calculated using the formula π * r2, where r is the radius of the circle and π is a mathematical constant approximately equal to 3.14159. The perimeter (circumference) of a circle is calculated using the formula 2 * π * r. we will create a function and pass the value of radius and return the area and perimeter. Example: This example shows the implementation of the above-approach.
Output Area of Circle: 452.38896 Perimeter of Circle: 75.39816 Using PHP’s Math FunctionsPHP provides built-in math functions that can be used to calculate the area and perimeter of a circle. To find the area, we use the formula M_PI * $radius * $radius, and to find perimeter, we use the formula 2 * M_PI * $radius, where M_PI is represents the mathematical pie value. Example: This example shows the implementation of the above-explained approach.
Output Area of Circle: 452.38934211693 Perimeter of Circle: 452.38934211693 |
Reffered: https://www.geeksforgeeks.org
PHP |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |