find the surface area of a cone in csharp

To find the surface area of a cone in C#, you need to use the formula:

main.cs
surface area = πr² + πrl
25 chars
2 lines

Where r is the radius of the base of the cone, h is the height of the cone, and l is the slant height of the cone, which can be calculated using the Pythagorean theorem as l = √(r² + h²).

Here's the C# code to find the surface area of a cone:

main.cs
using System;

public class Cone
{
    public static double SurfaceArea(double r, double h)
    {
        double l = Math.Sqrt(r * r + h * h);
        double surfaceArea = Math.PI * r * r + Math.PI * r * l;
        return surfaceArea;
    }
}

// Example usage:
double radius = 5;
double height = 10;
double surfaceArea = Cone.SurfaceArea(radius, height);
Console.WriteLine("Surface area of cone with radius {0} and height {1} is {2}", radius, height, surfaceArea);
466 chars
18 lines

In this example, we create a Cone class with a static method SurfaceArea, which takes the radius r and height h as input parameters, calculates the slant height l, then calculates and returns the surface area of the cone using the formula.

We then use this method to find the surface area of a cone with radius 5 and height 10, and print the result to the console.

gistlibby LogSnag