Program to find Surface Area and Volume of Octagonal Prism

18 Mar, 2021
Given the base length, height, and distance of Octagonal Prism we have to find the Surface Area and Volume of the octagonal prism for the given parameters. The octagonal prism is a solid three-dimensional object having a total of 10 faces, 24 edges, and 16 vertices. The two faces at either end are octagons and the rest of the faces are rectangular. 
where a is the base length, h is height and d is the distance of octagonal prism.  
Area = 2 * base * distance Surface area = (2 * Area) + ( 8 * base * height ) Volume = ( Area * height )
Examples: 
Input: h = 2, a = 4, d = 3 Output: Surface Area : 112 Volume : 48Input: h = 1, a = 6, d = 2 Output: Surface Area : 96 Volume : 24  
 
C++
Java
Python3
C#
Javascript
// C++ program to find the// Surface area and volume// of octagonal prism#include <iostream>using namespace std; // Function to find the// Volume of octagonal prismvoid find_volume(float area, float h){    // Formula to calculate    // volume = (area * h)    float Volume = (area * h);         // Display volume    cout << "Volume: "         << Volume << endl;}     // Function to find the// surface area of octagonal prismvoid find_Surface_area(float area,                       float a, float h){             // Formula to calculate Surface area    float Surface_area = (2 * area) +                         (8 * a * h);         cout << "Surface area: "         << Surface_area << endl;} // Driver Codeint main(){    float h = 1;    float a = 6;    float d = 2;    float area = 2 * a * d;         find_Surface_area(area, a, h);         find_volume(area, h);         return 0;} // This code is contributed by AnkitRai01
// Java program to find the// Surface area and volume// of octagonal prismpublic class GFG {     // Function to find the    // Volume of octagonal prism    static void find_volume(double area,double h){                 // Formula to calculate        // volume = (area * h)        double Volume = (area * h) ;                 // Display volume        System.out.println("Volume: " + Volume);    }         // Function to find the    // surface area of octagonal prism    static void find_Surface_area(double area, double a, double h){                 // Formula to calculate Surface area        double Surface_area = (2 * area)+(8 * a * h) ;                 System.out.println("Surface area: " + Surface_area) ;    }     // Driver Code    public static void main (String[] args)    {        double h = 1 ;        double a = 6 ;        double d = 2 ;        double area = 2 * a * d ;                          find_Surface_area(area, a, h) ;                 find_volume(area, h) ;         }} // This code is contributed by AnkitRai01
# Python3 program to find the# Surface area and volume# of octagonal prismimport math      # Function to find the# Volume of octagonal prismdef find_volume(area, h):         # Formula to calculate    # volume = (area * h)    Volume = (area * h)         # Display volume    print("Volume: ", end =" ")    print(Volume) # Function to find the# surface area of octagonal prismdef find_Surface_area(area, a, h):         # Formula to calculate Surface area    Surface_area = (2 * area)+(8 * a * h)         print("Surface area: ", end =" ")    print(Surface_area)     # Driver Codeh = 1a = 6d = 2area = 2 * a * d  find_Surface_area(area, a, h) find_volume(area, h)
// C# program to find the surface area// and volume of octagonal prismusing System; class GFG { // Function to find the volume// of octagonal prismstatic void find_volume(double area, double h){             // Formula to calculate    // volume = (area * h)    double Volume = (area * h);             // Display volume    Console.WriteLine("Volume: " + Volume);}     // Function to find the surface // area of octagonal prismstatic void find_Surface_area(double area, double a,                                           double h){             // Formula to calculate surface area    double Surface_area = (2 * area) + (8 * a * h);         Console.WriteLine("Surface area: " + Surface_area);} // Driver Codepublic static void Main (string[] args){    double h = 1;    double a = 6;    double d = 2;    double area = 2 * a * d;         find_Surface_area(area, a, h);    find_volume(area, h);}} // This code is contributed by AnkitRai01
<script>// javascript program to find the// Surface area and volume// of octagonal prism // Function to find the// Volume of octagonal prismfunction find_volume( area,  h){     // Formula to calculate    // volume = (area * h)    let Volume = (area * h);         // Display volume    document.write( "Volume: "         + Volume +"<br/>");}     // Function to find the// surface area of octagonal prismfunction find_Surface_area( area,                        a,  h){             // Formula to calculate Surface area    let Surface_area = (2 * area) +                         (8 * a * h);         document.write("Surface area: "         +Surface_area  +"<br/>");} // Driver Code    let h = 1;    let a = 6;    let d = 2;    let area = 2 * a * d;    find_Surface_area(area, a, h);    find_volume(area, h);     // This code is contributed by todaysgaurav </script>
Surface area:  96
Volume:  24
 
ankthon
todaysgaurav
Aptitude
Engineering Mathematics
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Order and Ranking Questions & Answers
Puzzle | How much money did the man have before entering the bank?
Aptitude | Arithmetic Aptitude 2 | Question 8
Seating Arrangement | Aptitude
Aptitude | GATE CS 1998 | Question 48
Relationship between number of nodes and height of binary tree
Difference between Propositional Logic and Predicate Logic
Inequalities in LaTeX
Arrow Symbols in LaTeX
Mathematics | Introduction to Propositional Logic | Set 1