PHP program that accepts the dimensions of a cylinder and prints its surface area and volume:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php function surfaceArea($radius, $height) { return 2 * pi() * $radius * $height + 2 * pi() * pow($radius, 2); } function volume($radius, $height) { return pi() * pow($radius, 2) * $height; } $radius = readline("Enter the radius of the cylinder: "); $height = readline("Enter the height of the cylinder: "); $surfaceArea = surfaceArea($radius, $height); $volume = volume($radius, $height); echo "The surface area of the cylinder is: " . $surfaceArea . "\n"; echo "The volume of the cylinder is: " . $volume . "\n"; |
In this program, the surfaceArea
function calculates the surface area of a cylinder given its $radius
and $height
. The volume
function calculates the volume of a cylinder given its $radius
and $height
.
The program prompts the user to enter the radius and height of the cylinder using the readline
function. It then calls the surfaceArea
and volume
functions and assigns the results to variables $surfaceArea
and $volume
. Finally, it prints the surface area and volume of the cylinder to the screen.