Program to compute the area and perimeter of Hexagon

Problem statement:-  Program to compute the area and perimeter of the hexagon.

Formula:

Area Of Hexagon(A):



where a=side length of the Hexagon



Perimeter of Hexagon(P):

P
=
6a

 Data requirement:-

   Input Data:- a

  Output Data:- area, perimeter

Program in C

Here is the source code of the C Program to compute the area and perimeter of the hexagon.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    printf("Enter the length of the side:");
    int a;
    scanf("%d",&a);
    double area=(3*sqrt(3)*pow(a,2))/2.0;
    int perimeter=(6*a);
    printf("Area of the Hexagon = %lf\n",area);
    printf("Perimeter of the Hexagon = %d",perimeter);
}

Input/Output:
Enter the length of the side:5
Area of the Hexagon = 64.951905
Perimeter of the Hexagon = 30

Program in C++

Here is the source code of the C++ Program to compute the area and perimeter of the hexagon.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    cout<<"Enter the length of the side:";
    int a;
    cin>>a;
    double area=(3*sqrt(3)*pow(a,2))/2.0;
    int perimeter=(6*a);
    cout<<"Area of the Hexagon = "<<area;
    cout<<"\nPerimeter of the Hexagon = "<<perimeter;
}

Input/Output:
Enter the length of the side:8
Area of the Hexagon = 166.277
Perimeter of the Hexagon = 48

Program in Java
  
Here is the source code of the Java Program to compute the area and perimeter of the hexagon.

Code:

import java.util.Scanner;
public class Area_Perimeter_Hexagon {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the length of the side:");
    int a=cs.nextInt();
    double area=(3*Math.sqrt(3)*Math.pow(a,2))/2.0;
    int perimeter=(6*a);
    System.out.println("Area of the Hexagon = "+area);
    System.out.println("Perimeter of the Hexagon = "+perimeter);
cs.close();
}
}

Input/Output:
Enter the length of the side:
10
Area of the Hexagon = 259.8076211353316
Perimeter of the Hexagon = 60

Program in Python
  
Here is the source code of the Python Program to compute the area and perimeter of the hexagon.

Code:

import math
print("Enter the length of the side:")
a=int(input())
area=(3*math.sqrt(3)*math.pow(a,2))/2.0
perimeter=(6*a)
print("Area of the Hexagon = ",area)
print("Perimeter of the Hexagon = ",perimeter)

Input/Output:

Post a Comment

0 Comments