Q:

Write a Program to find the Volume of a Hexagonal Prism

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the Volume of a hexagonal prism in different programming languages, firstly we have to know about the hexagonal prism and its volume's formula.

What is Hexagonal Prism?

Hexagonal Prism is a 3-D shape, which has 8 faces, 12 vertices, and 18 edges.

Area of Hexagonal Prism

 

Volume of Hexagonal Prism = 3 * √3 * a * a * h / 2  

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program of calculating the Volume of a hexagonal prism in different Programming languages

Program 1: Write a Program in C language:

// This program which uses a function to find the Volume of a hexagonal prism .  
#include <stdio.h>  
#include <math.h>  
float find_Volume_of_Hexagonal_prism(float a, float h) // It is a function to find Volume   
{   
float Volume_of_Hexagonal_prism ;  
Volume_of_Hexagonal_prism = 3 * sqrt(3) * a * a * h / 2; // It is a formula for calculating the Volume of hexagonal prism    
return (Volume_of_Hexagonal_prism );   
}   
float main()   
{   
float a = 4.55, h = 9.10;  
printf("Volume of the hexagonal prism  is: %f", find_Volume_of_Hexagonal_prism(a, h));     
return 0;   
}  

 

Output of Above C program:

Volume of the hexagonal prism  is: 489.458771

 

Program 2: Write a Program in Java language:

// This Java program which finds the Volume of a hexagonal prism .  
class findVolume {   
static double find_Volume_of_Hexagonal_prism( float a, float h)  
{    
double Volume_of_Hexagonal_prism ;  
Volume_of_Hexagonal_prism = 3 * Math.sqrt(3) * a * a * h / 2; // It is a formula for calculating the Volume of hexagonal prism    
return(Volume_of_Hexagonal_prism);   
}   
  
// Driver method   
public static void main(String[] args)   
{   
float a = 20;  
float h = 10;  
System.out.println("The Volume of a hexagonal prism  is:");  
System.out.println(find_Volume_of_Hexagonal_prism(a, h));   
}   
}  

 

Output of Above Java program:

The Volume of a hexagonal prism is:
10392.304845413264

 

Program 3: Write a Program in PHP programming language.

<?php   
// This PHP program which finds the Volume of a hexagonal prism.    
// Function to find Volume   
function find_Volume_of_Hexagonal_prism($a, $h)   
{     
$Volume_of_Hexagonal_prism  = 3 * sqrt(3) * $a * $a * $h / 2; // It is an statement which uses a forumla to find the Volume and store the value in the Volume_of_hexagonal prism variable.   
return ($Volume_of_Hexagonal_prism);   
}   
$a = 4;   
$h = 4;    
echo find_Volume_of_Hexagonal_prism($a, $h);   
  
?>  

 

Output of Above PHP program:

166.27687752661

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the Volume of a hexagonal prism.  
from math import sqrt  
def find_Volume_of_Hexagonal_prism(a, h):  
    return ( 3 * sqrt(3) * a * a * h / 2) # It is a formula which finds the value of Volume.  
# main code begins   
a = 9;   
h = 2;    
print(find_Volume_of_Hexagonal_prism(a, h) )  

 

Output of Above Python program:

420.8883462392372

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Miscellaneous Programs Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a program to find the Volume of the Rectangu... >>
<< Write a Program to find the Area of Hexagonal Pris...