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)