How to calculate the area of a pentagon in PHP

2 Answers

0 votes
function pentagon_area($side, $apothem) {
    return 5.0 * ($side * $apothem) / 2.0;
}

$side = 5.0;
$apothem = 3.0;

$area = pentagon_area($side, $apothem);

echo "Area = " . number_format($area, 2) . "\n";


/*
run:

Area = 37.50

*/

 



answered Jul 12, 2021 by avibootz
edited 8 hours ago by avibootz
0 votes
function area_regular_pentagon(float $side): float {
    return (1 / 4) * sqrt(5 * (5 + 2 * sqrt(5))) * ($side ** 2);
}

echo area_regular_pentagon(7), "\n";


/*
run:

84.303392628859

*/

 



answered 2 hours ago by avibootz
...