Program to find volume and surface area of pentagonal prism

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++
// 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
// 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));}} |
Python3
# 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#
// 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// 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?> |
Javascript
<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> |
Output:Â
surface area= 180, volume= 52.5
Â
Time complexity: O(1)
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!




