Reputation: 3
I need some guidance as I have code below i need to solve and I'm not sure if I've done them correctly or not because I feel they are right and I am getting an output but I'm not sure if its the right output.
Basically I need to find the circumference and area, when the given radius is 20.0. I have the need equation at the top of each code snippet. I just want to know if I am right or along the right tracks as I'am new to PHP.
//π΄πππ = ππ2//
$r = 20.0;
$Area = pi() * (pow($r,2)); //PI = 3.1415926535898
echo $Area, '<br/>';
//πΆππππ’ππππππππ = 2ππ//
$Circumference = 2 * pi() * $r;
echo $Circumference, '<br/>';
Upvotes: 0
Views: 146
Reputation: 185
Seems fine. Also, put 4 spaces for each code so that they can be showed to others as code snippet. Otherwise, your code will not likely to be easy-readable.
Upvotes: 0
Reputation: 3230
You code is working properly.
Area
//π΄πππ = ππ2//
$r = 20.0;
$Area = pi() * (pow($r,2)); //PI = 3.1415926535898
echo $Area, '<br/>';
Your output: 1256.6370614359
Google output:
Circumference
//πΆππππ’ππππππππ = 2ππ//
$Circumference = 2 * pi() * $r;
echo $Circumference, '<br/>';
Your output: 125.66370614359
Google output:
You could make it a little bit better by adding functions:
function calculateCircleArea($r) {
return pi() * (pow($r,2));
}
function calculateCircleCircumference($r) {
return 2 * pi() * $r;
}
echo calculateCircleArea(20.0).'<br/>';
echo calculateCircleCircumference(20.0);
Upvotes: 1