Create a program to compute the volume of a sphere. Use the formula: V= (4/3)*πr 3 where π is equal to 3.1416 approximately. The variable r is the radius. Display the volume of a sphere.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace C_SHARP
{
class Program
{
static double getRadius()
{
Console.Write("Enter a radius of sphere: ");
return double.Parse(Console.ReadLine());
}
static void Main(string[] args)
{
double radius = getRadius();
double volume = (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3.0);
Console.WriteLine("The volume of a sphere is {0}",volume.ToString("N2"));
Console.ReadLine();
}
}
}
Comments
Leave a comment