find the volume of a cube in csharp

To find the volume of a cube in C#, you need to use the formula V = s^3 where V is the volume and s is the length of one side of the cube.

Here is the code to find the volume of a cube in C#:

main.cs
double side = 5.0; // length of one side
double volume = Math.Pow(side, 3); // use the formula to calculate the volume
Console.WriteLine("Volume of the cube is: " + volume + " cubic units");
191 chars
4 lines

In this example, the length of one side of the cube is 5.0. By using Math.Pow method we can find the cube of side. Then we print out the volume in cubic units using Console.WriteLine statement.

The output for this code will be:

main.cs
Volume of the cube is: 125 cubic units
39 chars
2 lines

gistlibby LogSnag