Surface Area and Volume of Hexagonal Prism

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.

hexagonal prism

where a is the base length and h is the height of the hexagonal prism.

 

 

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++

// C++ program to find the Surface Area

// and Volume of Hexagonal Prism.

  

#include <bits/stdc++.h>

using namespace std;

  

// Function to calculate Surface area

void findSurfaceArea(float a, float h)

{

    float Area;

  

    // Formula to calculate surface area

    Area = 6 * a * h + 3 * sqrt(3) * a * a;

  

    // Display surface area

    cout << "Surface Area: " << Area;

    cout << "\n";

}

  

// Function to calculate Volume

void findVolume(float a, float h)

{

    float Volume;

  

    // formula to calculate Volume

    Volume = 3 * sqrt(3) * a * a * h / 2;

  

    // Display Volume

    cout << "Volume: " << Volume;

}

  

// Driver Code

int main()

{

    float a = 5, h = 10;

      

    // surface area function call

    findSurfaceArea(a, h);

  

    // volume function call

    findVolume(a, h);

  

    return 0;

}