Write a complete C# app to prompt the user for the double radius of a sphere, and call method SphereVolume to calculate and display the volume of the sphere. Write an expression-bodied method containing the following expression to calculate the volume:
(4.0 / 3.0) * Math.PI * Math.Pow(radius, 3)
```
// Solution: Sphere.cs
// Calculate the volume of a sphere.
using System;
class Sphere
{
// obtain radius from user and display volume of sphere
static void Main()
{
Console.Write("Enter radius of sphere: ");
double radius = double.Parse(Console.ReadLine());
Console.WriteLine("Volume is {SphereVolume(radius):F3}");
}
// calculate and return sphere volume
static double SphereVolume(double radius) =>
(4.0 / 3.0) * Math.PI * Math.Pow(radius, 3);
}
```
Enter radius of sphere: 4
Volume is 268.083
You might also like to view...
The style of a paragraph cannot be changed without highlighting the paragraph to be altered
Indicate whether the statement is true or false
What kind of iterators does the stack template container have?
What will be an ideal response?