Infolinks

Breaking

Adsense

Wednesday, January 27, 2016

PHP CIRCLE AREA: Solve for the Area and Circumference of A Circle

Hi there! The following tutorial will introduce you to one of the most common problems encountered in programming subjects. Later on, I will provide set of activities and quizzes for you to practice on to improve your programming skills.

Area solver for shapes is just one of the exercises given by most programming instructors. Some other exercises are the following:

1. Celsius to Fahrenheit Temperature Converter
2. Identify if odd or even number
3. Display numbers using a for loop
4. Solve for the area of a triangle
5. Fibonacci Series

and many more. These are just some of the activities that I posted here in my blog. You can visit the links if you want.

Area is the size of the surface of an object. In this article, we will discuss about the formula and php code in solving for the area of a circle.

Try PHP Circle Area Live Here!



Formula area of circle



a = to the length of the side
r = radius of a circle
pi = 3.1415926535898

PHP Code
<?php
$radius = 10;
$area = pi()*pow($radius,2);
echo "The area of the square with the side of $radius is $area";
?>
I used the pi() function but you can also declare a variable with the value of 3.1415926535898. The pow() function is used to express exponential values. Let's say pow($radius,2) means the value of $radius will be raised to 2 with the value of 10 for the $radius.

Output area of circle



Circumference of a Circle Formula

Circumference = 2 × π × r

PHP Code circumference of a circle

<?php
$radius = 10;
$circumference = 2 * pi()*$radius;
echo "The circumference of the circle with the radius of $radius is $circumference";
?>

Output circumference of a circle



If you want your output to be formatted in 2 decimal places, just do it this way. 
echo number_format($circumference,2);

Thank you for visiting and hope this helps you. Feel free to leave a comment below for any questions. I got some other articles related to php and mysql here in my blog. Watch out for more upcoming tutorials related to blogging and programming. Good day! ^_^

PHP CIRCLE AREA: Solve for the Area and Circumference of A Circle

No comments:

Post a Comment

Adbox