1. Calculate the area of a pentagon. Ask the user to enter the length from the c
ID: 3753166 • Letter: 1
Question
1. Calculate the area of a pentagon. Ask the user to enter the length from the center of a pentagon to a vertex, then compute the area of the pentagon. The formula for computing the area of a pentagon is: Area = Where s is the length of a side. The length of a side can be computed by using 3V3 2 2 the formula: s 2r sin Where r is the length from the center of the pentagon to a vertex. Format your answer to two decimal places. Here is a sample run: Enter the length from the center to a vertex: 5.5 The area of the pentagon is 108.61Explanation / Answer
You have not mentioned the programming language.
Python:
--------
import math
r = float(input("Enter the length from the center to a vertex: "))
s = 2 * r * math.sin(math.pi/5)
area = 3 * math.sqrt(3) / 2 * s * s;
print("The area of the pentagon is {:.2f}".format(area))
Java:
--------
import java.util.Scanner;
public class PentagonArea {
public static void main(String[] args) {
double r, s;
Scanner keyboard = new Scanner(System.in);
double area;
System.out.print("Enter the length from the center to a vertex: ");
r = keyboard.nextDouble();
s = 2 * r * Math.sin(Math.PI/5);
area = 3 * Math.sqrt(3) / 2 * s * s;
System.out.printf("The area of the pentagon is %.2f ", area);
}
}
output
-----
Enter the length from the center to a vertex: 5.5
The area of the pentagon is 108.61
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.