Program to find volume and surface area of pentagonal prism

28 Jun, 2022
A prism that has 5 rectangular faces and 2 parallel pentagonal bases is a pentagonal prism. So you are given the apothem length(a), base length(b) and height(h) of the pentagonal prism. you have to find the surface area and the volume of the Pentagonal Prism.Examples:  
Input : a=3, b=5, h=6
Output :surface area=225, volume=225

Input : a=2, b=3, h=5
Output :surface area=105, volume=75
 
In this figure, a– apothem length of the Pentagonal Prism. b– base length of the Pentagonal Prism. h– height of the Pentagonal Prism.Formulas:Below are the formulas for calculating the surface area and the volume of the Pentagonal Prism.
    
    
 
C++
Java
Python3
C#
PHP
Javascript
// CPP program to find// surface area and volume of the// Pentagonal Prism#include <bits/stdc++.h>using namespace std; // function for surface areafloat surfaceArea(float a, float b, float h){    return 5 * a * b + 5 * b * h;} // function for VOlumefloat volume(float b, float h){    return (5 * b * h) / 2;} // Driver functionint main(){    float a = 5;    float b = 3;    float h = 7;     cout << "surface area= " << surfaceArea(a, b, h) << ", ";     cout << "volume= " << volume(b, h);}
// Java program to find// surface area and volume of the// Pentagonal Prismimport java.util.*; class solution{ // function for surface areastatic float surfaceArea(float a, float b, float h){     return 5 * a * b + 5 * b * h; } // function for VOlumestatic float volume(float b, float h){     return (5 * b * h) / 2; } // Driver functionpublic static void main(String arr[]){    float a = 5;    float b = 3;    float h = 7;     System.out.println( "surface area= "+surfaceArea(a, b, h)+", ");     System.out.println("volume= "+volume(b, h));}}
# Python 3 program to find surface area# and volume of the Pentagonal Prism # function for surface areadef surfaceArea(a, b, h):    return 5 * a * b + 5 * b * h # function for VOlumedef volume(b, h):    return (5 * b * h) / 2 # Driver Codeif __name__ == '__main__':    a = 5    b = 3    h = 7     print("surface area =", surfaceArea(a, b, h),                   ",", "volume =", volume(b, h)) # This code is contributed by# Sanjit_Prasad
// C# program to find surface// area and volume of the// Pentagonal Prismusing System; class GFG{ // function for surface areastatic float surfaceArea(float a,                         float b, float h){    return 5 * a * b + 5 * b * h;} // function for VOlumestatic float volume(float b, float h){    return (5 * b * h) / 2;} // Driver Codepublic static void Main(){    float a = 5;    float b = 3;    float h = 7;     Console.WriteLine("surface area = " +            surfaceArea(a, b, h) + ", ");     Console.WriteLine("volume = " +                     volume(b, h));}} // This code is contributed by vt_m
<?php// PHP program to find// surface area and volume// of the Pentagonal Prism // function for surface areafunction surfaceArea($a, $b, $h){    return 5 * $a * $b +           5 * $b * $h;} // function for VOlumefunction volume($b, $h){    return (5 * $b * $h) / 2;} // Driver Code$a = 5;$b = 3;$h = 7; echo "surface area = " ,      surfaceArea($a, $b, $h) , ", "; echo "volume = " , volume($b, $h); // This code is contributed by vt_m?>
<script>// javascript program to find// surface area and volume of the// Pentagonal Prism // function for surface areafunction surfaceArea( a,  b,  h){    return 5 * a * b + 5 * b * h;} // function for VOlumefunction volume( b,  h){    return (5 * b * h) / 2;} // Driver function    let a = 5;    let b = 3;    let h = 7;     document.write( "surface area= " + surfaceArea(a, b, h) + ", ");     document.write( "volume= " + volume(b, h));     // This code is contributed by todaysgaurav </script>
surface area= 180, volume= 52.5
 
Time complexity: O(1)
Auxiliary Space: O(1)
SURENDRA_GANGWAR
vt_m
Sanjit_Prasad
todaysgaurav
vinayedula
krishnav4
area-volume-programs
Geometric
School Programming
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.