Calculate the volume of a sphere. - CSharp Custom Type

CSharp examples for Custom Type:Lambda

Description

Calculate the volume of a sphere.

Demo Code

using System;/*  ww  w  .j  a va  2 s  .  com*/
class Sphere
{
   static void Main()
   {
      Console.Write("Enter radius of sphere: ");
      double radius = double.Parse(Console.ReadLine());
      Console.WriteLine($"Volume is {SphereVolume(radius):F3}");
   }
   static double SphereVolume(double radius) => (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3);
}

Result


Related Tutorials