Q:

Write a Program to find the Area of Hexagonal Prism

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the area of a hexagonal prism in different programming languages, firstly we have to know about the hexagonal prism and its formulae of surface area.

What is Hexagonal Prism?

Hexagonal Prism is a 3-D shape, which has 8 faces, 12 vertices, and 18 edges. The two faces at either ends of the prism are hexagons, and the rest of the faces of the hexagonal prism are rectangular.

Area of Hexagonal Prism

 

Surface area of Hexagonal Prism = (6 * a * h) + (3 * √3 * a * a)  

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 area 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 area of a hexagonal prism .  
#include <stdio.h>  
#include <math.h>  
float find_area_of_Hexagonal_prism(float a, float h) // It is a function to find area   
{   
float area_of_Hexagonal_prism ;  
area_of_Hexagonal_prism =  ((6 * a * h) + (3 * sqrt(3) * a * a)); // It is a formula for calculating the area of hexagonal prism    
return (area_of_Hexagonal_prism );   
}   
float main()   
{   
float a = 4.55, h = 9.10;  
printf("Surface area of the hexagonal prism  is: %f", find_area_of_Hexagonal_prism(a, h));     
return 0;   
}   

 

Output of Above C program:

Surface area of the hexagonal prism  is: 356.003387

 

Program 2: Write a Program in Java language:

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

 

Output of Above Java program:

The area of a hexagonal prism is:
3278.460969082653

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which finds the area of a hexagonal prism.    
// Function to find area   
function find_area_of_Hexagonal_prism($a, $h)   
{     
$area_of_Hexagonal_prism  =(6 * $a * $h) + (3 * sqrt(3) * $a * $a); // It is an statement which uses a forumla to find the surface area and store the value in the area_of_hexagonal prism variable.   
return ($area_of_Hexagonal_prism);   
}   
$a = 4;   
$h = 4;    
echo find_area_of_Hexagonal_prism($a, $h);   
?>  

 

Output of Above PHP program:

179.13843876331

 

Program 4: Write a Program in Python programming language.

# This is a python program which finds the area of a hexagonal prism .   
from math import sqrt  
def find_area_of_Hexagonal_prism(a, h):  
    return ( (6 * a * h) + (3 * sqrt(3) * a * a)) # It is a formula which finds the value of area.  
# main code begins   
a = 4;   
h = 4;    
print(find_area_of_Hexagonal_prism(a, h) )  

 

Output of Above Python program:

179.1384387633061

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 a Hexagonal ... >>
<< Write a program to find the Surface Area of a Tria...