How to find Volume and Surface Area of a Sphere using C#?

CsharpProgrammingServer Side Programming

For volume and surface area of a sphere, firstly declare a variable with the value of radius.

int r = 15;

Get the volume f the sphere.

// calculating volume of sphere
cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;

Now the surface area of the sphere is calculated −

cal_area = 4 * (22 / 7) * r * r;

Let us see the complete code −

Example

 Live Demo

using System;
using System.Collections.Generic;

public class Demo {
   public static void Main(string[] args) {
      double cal_area, cal_volume, r;
      // radius
      r = 15;

      // calculating area of sphere
      cal_area = 4 * (22 / 7) * r * r;

      // calculating volume of sphere
      cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;

      Console.WriteLine("Area of Sphere: " + cal_area);
      Console.WriteLine("Volume of Sphere: " + cal_volume);
   }
}

Output

Area of Sphere: 2700
Volume of Sphere: 13500
raja
Published on 21-Aug-2018 09:48:28
Advertisements