Program to find Surface Area and Volume of Octagonal Prism
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 : 48
Input: h = 1, a = 6, d = 2
Output:
Surface Area : 96
Volume : 24
C++
#include <iostream>
using namespace std;
void find_volume( float area, float h)
{
float Volume = (area * h);
cout << "Volume: "
<< Volume << endl;
}
void find_Surface_area( float area,
float a, float h)
{
float Surface_area = (2 * area) +
(8 * a * h);
cout << "Surface area: "
<< Surface_area << endl;
}
int 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;
}
|
Java
public class GFG {
static void find_volume( double area, double h){
double Volume = (area * h) ;
System.out.println( "Volume: " + Volume);
}
static void find_Surface_area( double area, double a, double h){
double Surface_area = ( 2 * area)+( 8 * a * h) ;
System.out.println( "Surface area: " + Surface_area) ;
}
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) ;
}
}
|
Python3
import math
def find_volume(area, h):
Volume = (area * h)
print ( "Volume: " , end = " " )
print (Volume)
def find_Surface_area(area, a, h):
Surface_area = ( 2 * area) + ( 8 * a * h)
print ( "Surface area: " , end = " " )
print (Surface_area)
h = 1
a = 6
d = 2
area = 2 * a * d
find_Surface_area(area, a, h)
find_volume(area, h)
|
C#
using System;
class GFG {
static void find_volume( double area, double h)
{
double Volume = (area * h);
Console.WriteLine( "Volume: " + Volume);
}
static void find_Surface_area( double area, double a,
double h)
{
double Surface_area = (2 * area) + (8 * a * h);
Console.WriteLine( "Surface area: " + Surface_area);
}
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);
}
}
|
Javascript
<script>
function find_volume( area, h)
{
let Volume = (area * h);
document.write( "Volume: "
+ Volume + "<br/>" );
}
function find_Surface_area( area,
a, h)
{
let Surface_area = (2 * area) +
(8 * a * h);
document.write( "Surface area: "
+Surface_area + "<br/>" );
}
let h = 1;
let a = 6;
let d = 2;
let area = 2 * a * d;
find_Surface_area(area, a, h);
find_volume(area, h);
</script>
|
Output:
Surface area: 96
Volume: 24
Time complexity: O(1) because performing constant operations
Auxiliary Space: O(1)
Last Updated :
31 Jul, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...