Program to compute the area and perimeter of Pentagon

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

Formula:

Area Of Pentagon(A):


where a=side length of the Pentagon


Perimeter of Pentagon(P):

P
  
=
  
5a

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

Code:

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

Input/Output:
Enter the length of the side:5
Area of the Pentagon = 43.011935
Perimeter of the Pentagon = 25

Program in C++

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

Code:

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

Input/Output:
Enter the length of the side:7
Area of the Pentagon = 84.3034
Perimeter of the Pentagon = 35

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

Code:

import java.util.Scanner;
public class Area_Perimeter_Pentagon {

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

Input/Output:
Enter the length of the side:
10
Area of the Pentagon = 172.0477400588967
Perimeter of the Pentagon = 50


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

Code:

import math
print("Enter the length of the side:")
a=int(input())
area=(math.sqrt(5*(5+2*math.sqrt(5)))*pow(a,2))/4.0
perimeter=(5*a)
print("Area of the Pentagon = ",area)

print("Perimeter of the Pentagon = ",perimeter)

Input/Output:

Post a Comment

0 Comments