Program to compute the area and perimeter of Heptagon

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

Formula:

Area Of Heptagon(A):

The above equation is approximately equal to
A = 3.634a2 
where a=side length of the Heptagon


Perimeter of Heptagon(P):

P
=
7a

 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 Heptagon.

Code:

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

Input/Output:
Enter the length of the side:5
Area of the Heptagon = 90.85
Perimeter of the Heptagon = 35

Program in C++

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

Code:

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

Input/Output:
Enter the length of the side:7
Area of the Heptagon = 178.066
Perimeter of the Heptagon = 49

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

Code:

import java.util.Scanner;
public class Area_Perimeter_Heptagon {

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.634*Math.pow(a,2);
    int perimeter=(7*a);
    System.out.println("Area of the Heptagon = "+area);
    System.out.println("Perimeter of the Heptagon = "+perimeter);
cs.close();
}
}

Input/Output:
Enter the length of the side:
10
Area of the Heptagon = 363.4
Perimeter of the Heptagon = 70

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

Code:

import math
print("Enter the length of the side:")
a=int(input())
area=3.634*pow(a,2)
perimeter=(7*a)
print("Area of the Heptagon = ",area)
print("Perimeter of the Heptagon= ",perimeter)

Input/Output:

Post a Comment

0 Comments