find the volume of a regular polygon circumscribed around a cone in csharp

Here's the code to find the volume of a regular polygon circumscribed around a cone in C#:

main.cs
using System;

class Program
{
    static void Main(string[] args)
    {
        // inputs
        int numSides = 6; // number of sides of the polygon
        double sideLength = 5.0; // length of each side of the polygon
        double coneRadius = 3.0; // radius of the circumscribed cone
        double coneHeight = 8.0; // height of the circumscribed cone

        // calculations
        double polygonPerimeter = numSides * sideLength; // perimeter of the regular polygon
        double polygonApothem = coneRadius; // apothem of the regular polygon
        double polygonArea = (1.0 / 2.0) * polygonPerimeter * polygonApothem; // area of the regular polygon
        double coneVolume = (1.0 / 3.0) * Math.PI * Math.Pow(coneRadius, 2) * coneHeight; // volume of the circumscribed cone
        double polygonHeight = coneHeight - ((coneRadius * Math.Tan(Math.PI / numSides)) * 2); // height of the regular polygon
        double polygonVolume = polygonArea * polygonHeight; // volume of the regular polygon

        double totalVolume = coneVolume + polygonVolume; // total volume of the shape

        // output
        Console.WriteLine("The volume of the regular polygon circumscribed around a cone is: " + totalVolume);
    }
}
1237 chars
27 lines

Note: This code assumes a fixed number of sides for the regular polygon. To make it more flexible, you can replace numSides and sideLength with user inputs.

gistlibby LogSnag