# C# - Calculate the Volume of Sphere

Here, we are going to learn how to calculate the volume of Sphere in C#?
Submitted by Nidhi, on October 11, 2020 [Last updated : March 17, 2023]

## Volume of Sphere Formula

Here, we will calculate the volume of Sphere using the below formula.

```volume = (float)(4.0 / 3 * Math.PI * radius * radius*radius);
```

## C# program to calculate the volume of Sphere

The source code to calculate the volume of the Sphere is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

```//C# program to calculate the volume of a Sphere.

using System;

class Sphere
{
{
float volume = 0.0F;

return volume;
}
public static void Main()
{
float volume = 0.0F;

Console.Write("Enter the value of radius: ");

Console.WriteLine("Volume of Sphere: " + volume);
}
}
```

## Output

```Enter the value of radius: 7
Volume of Sphere: 1436.755
Press any key to continue . . .
```

## Explanation

Here, we created a class Sphere that contains two methods CalculateVolume() and Main(). The CalculateVolume() method is used to calculate the volume of Sphere using the below formula and return the calculated volume to the calling method.

```volume = (float)(4.0 / 3 * Math.PI * radius * radius*radius);
```

In the Main() method, we created two local variables volume and radius initialized with 0. Then we read the value of the radius from the user after that passed the value of radius into the CalculateVolume() method that will return the calculated volume that will be printed on the console screen.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates