find the surface area of a cylinder in csharp

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

main.cs
surfaceArea = 2 * pi * radius * height + 2 * pi * radius^2
59 chars
2 lines

Here is the C# code to calculate the surface area of a cylinder:

main.cs
using System;

class Program {
    static void Main(string[] args) {
        double surfaceArea;
        double radius = 5;  // replace with your own values
        double height = 10; // replace with your own values

        const double pi = Math.PI;

        surfaceArea = 2 * pi * radius * height + 2 * pi * Math.Pow(radius, 2);

        Console.WriteLine("Surface area of the cylinder = {0}", surfaceArea);
    }
}
420 chars
16 lines

This program declares a surfaceArea variable, and initializes radius and height to 5 and 10 respectively (you can replace these values with your own input).

The const keyword is used to declare a constant variable pi with the value of Pi (3.14159). We use this value to avoid hard-coding Pi in the formula.

Finally, the program calculates the surface area of the cylinder using the formula provided above, and displays the result to the console.

gistlibby LogSnag