Given a Base edge and Height of the Hexagonal prism, the task is to find the Surface Area and the Volume of hexagonal Prism. In mathematics, a hexagonal prism is a three-dimensional solid shape which have 8 faces, 18 edges, and 12 vertices. The two faces at either ends are hexagons, and the rest of the faces of the hexagonal prism are rectangular.

where a is the base length and h is the height of the hexagonal prism.
Surface Area = 
Volume = 
Examples:
Input : a = 4, h = 3
Output : Surface Area: 155.138443
Volume: 124.707657
Input : a = 5, h = 10
Output : Surface Area: 429.904
Volume: 649.519
C++
#include <bits/stdc++.h>
using namespace std;
void findSurfaceArea( float a, float h)
{
float Area;
Area = 6 * a * h + 3 * sqrt (3) * a * a;
cout << "Surface Area: " << Area;
cout << "\n" ;
}
void findVolume( float a, float h)
{
float Volume;
Volume = 3 * sqrt (3) * a * a * h / 2;
cout << "Volume: " << Volume;
}
int main()
{
float a = 5, h = 10;
findSurfaceArea(a, h);
findVolume(a, h);
return 0;
}
|
Java
import java.io.*;
class GFG {
static void findSurfaceArea( float a, float h)
{
float Area;
Area = 6 * a * h + 3 * ( float )(Math.sqrt( 3 )) * a * a;
System.out.println( "Surface Area: " + Area);
}
static void findVolume( float a, float h)
{
float Volume;
Volume = 3 * ( float )(Math.sqrt( 3 )) * a * a * h / 2 ;
System.out.println( "Volume: " + Volume);
}
public static void main (String[] args)
{
float a = 5 , h = 10 ;
findSurfaceArea(a, h);
findVolume(a, h);
}
}
|
Python3
import math
def findSurfaceArea(a, h):
Area = 0 ;
Area = ( 6 * a * h +
3 * math.sqrt( 3 ) * a * a);
print ( "Surface Area:" ,
round (Area, 3 ));
def findVolume(a, h):
Volume = 0 ;
Volume = ( 3 * math.sqrt( 3 ) *
a * a * h / 2 );
print ( "Volume:" ,
round (Volume, 3 ));
a = 5 ;
h = 10 ;
findSurfaceArea(a, h);
findVolume(a, h);
|
C#
using System;
class GFG
{
static void findSurfaceArea( float a,
float h)
{
float Area;
Area = 6 * a * h + 3 *
( float )(Math.Sqrt(3)) * a * a;
Console.WriteLine( "Surface Area: " +
Area);
}
static void findVolume( float a,
float h)
{
float Volume;
Volume = 3 * ( float )(Math.Sqrt(3)) *
a * a * h / 2;
Console.WriteLine( "Volume: " +
Volume);
}
public static void Main ()
{
float a = 5, h = 10;
findSurfaceArea(a, h);
findVolume(a, h);
}
}
|
PHP
<?php
function findSurfaceArea( $a , $h )
{
$Area ;
$Area = 6 * $a * $h + 3 *
sqrt(3) * $a * $a ;
echo "Surface Area: " ,
$Area , "\n" ;
}
function findVolume( $a , $h )
{
$Volume ;
$Volume = 3 * sqrt(3) *
$a * $a * $h / 2;
echo "Volume: " , $Volume ;
}
$a = 5; $h = 10;
findSurfaceArea( $a , $h );
findVolume( $a , $h );
?>
|
Javascript
<script>
function findSurfaceArea( a, h)
{
let Area;
Area = 6 * a * h + 3 * Math.sqrt(3) * a * a;
document.write( "Surface Area: " + Area.toFixed(3) + "<br/>" );
}
function findVolume( a, h)
{
let Volume;
Volume = 3 * Math.sqrt(3) * a * a * h / 2;
document.write( "Volume: " + Volume.toFixed(3));
}
let a = 5, h = 10;
findSurfaceArea(a, h);
findVolume(a, h);
</script>
|
Time complexity : O(1) as performing constant operations
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 geeks!
Last Updated :
07 Aug, 2022
Like Article
Save Article