To find the surface area of a cylinder in C#, you can use the following formula:
main.cs59 chars2 lines
Here is the C# code to calculate the surface area of a cylinder:
main.cs420 chars16 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