find the area of a regular polygon in csharp

To find the area of a regular polygon in C#, you can use the following formula:

main.cs
Area = (n * s^2) / (4 * tan(pi / n))
37 chars
2 lines

where n is the number of sides of the polygon, s is the length of each side, pi is the mathematical constant pi, and tan is the tangent function.

Here's the C# code to implement the formula:

main.cs
using System;

class Program {
    static void Main(string[] args) {
        int n = 6; // number of sides
        double s = 5; // length of each side

        double area = (n * Math.Pow(s, 2)) / (4 * Math.Tan(Math.PI / n));
        Console.WriteLine("The area of the regular polygon is " + area);
    }
}
308 chars
12 lines

In this example, we have a regular hexagon with side length of 5 units. We calculate the area of the hexagon using the formula and output the result to the console.

gistlibby LogSnag