Geometry: Area of a Regular Polygon

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

<— Return Home

45.cpp

#include <iostream>
#include <cmath>
using namespace std;

int main(){
    double area;
    double s;
    double n;

    std::cout << "Enter the number of sides: \n";
    std::cin >> n;

    std::cout << "Enter the side: \n";
    std::cin >> s;

    area = (n * pow(s, 2)) / (4 * tan(M_PI / n));

    std::cout << "The area of the polygon is " << area << "\n";
}

<— Return Home