Q:

Write a Program to calculate the Perimeter of Hexagon

belongs to collection: Miscellaneous Programs Examples

0

Before writing the program of calculating the perimeter of hexagon in different programming languages, firstly we have to know about what is hexagon and what is the formula to find perimeter of it?

What is Hexagon?

A hexagon is a 6-sided, 2-dimensional geometric figure. The total of the internal angles of any hexagon is 720°. A regular hexagon has 6 rotational symmetries and 6 reflection symmetries. All internal angles are 120 degrees.

Perimeter of Hexagon = 6 * a,  

where, a is the side length of Hexagon.

All Answers

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

Program of calculating the perimeter of a hexagon in different Programming languages

Program 1: Write a Program in C language:

// This a C program which uses a function to find the perimeter of a hexagon.  
#include <stdio.h>  
float findPerimeterofhexagon(float a) // It is a function to find perimeter   
{   
float Perimeter_of_hexagon;  
Perimeter_of_hexagon= 6 * a; // It is a formula for calculating a perimeter of hexagon   
return (Perimeter_of_hexagon);   
}   
int main()   
{   
float side;   
printf("Enter the length of side of the hexagon:");   
scanf("%f",&side);  
printf("Perimeter of the hexagon is: %.2f", findPerimeterofhexagon(side));     
return 0;   
}   

 

Output of Above C program:

Enter the length of side of the hexagon:6
Perimeter of the hexagon is: 36.00

 

Program 2: Write a Program in Java language:

// This a  Java program which calculates the perimeter of a hexagon.  
class findperimeter {   
static int findPerimeterofhexagon(int a)   
{   
int Perimeter_of_hexagon;  
Perimeter_of_hexagon= 6 * a; // It is a formula for calculating the perimeter of hexagon   
return(Perimeter_of_hexagon);   
}   
  
// Driver method   
public static void main(String[] args)   
{   
int side = 20;   
System.out.println("The Perimeter of a hexagon in Java:");  
System.out.println(findPerimeterofhexagon(side));   
}   
}  

 

Output of Above Java program:

The Perimeter of a hexagon in Java:
120

 

Program 3: Write a Program in PHP programming language.

<?php   
// This a  PHP program which calculates the perimeter of a hexagon.    
// Function to find perimeter   
function findPerimeterofhexagon($a)   
{           
$Perimeter_of_hexagon = 6 * $a; // It is a formula which calculates the perimeter  and store the value in the perimeter variable.   
return ($Perimeter_of_hexagon);   
}   
  
$side = 40;   
  
echo findPerimeterofhexagon($side);   
  
?>  

 

Output of Above PHP program:

240

 

Program 4: Write a Program in Python programming language.

# This is a python program which calculates the perimeter of a hexagon.   
# It is a function to calculate the perimeter of hexagon  
def findPerimeterofhexagon(a):  
    return (6 * a) # It is a formula which adds the three side and # then return the value to the statement of calling fucntion.   
side =50  
print(findPerimeterofhexagon(side))  

 

Output of Above Python program:

300

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 calculate the Area of Rhombus... >>
<< Program to calculate Volume of Cone...