C# Program to Find Volume and Surface Area of Sphere

This is a C# Program to find volume and surface area of a sphere.

Problem Description

This C# Program finds Volume and Surface Area of a Sphere.

Problem Solution

Here radius and height of the sphere are obtained from the user and the surface area and its volume its calculated.

Program/Source Code

Here is source code of the C# Program to find Volume and Surface Area of a Sphere. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to find Volume and Surface Area of a Sphere
 */
using System;
using System.IO;
class program
{
    public static void Main()
    {
        double r, surface_area, volume;
        double PI = 3.14;
        Console.WriteLine("Enter the Radius of the Sphere: ");
        r = Convert.ToDouble(Console.ReadLine());
        surface_area =  4* PI * r * r;
        volume = (4.0 / 3) * PI * r * r * r;
        Console.WriteLine("Surface Area of Sphere is : {0} ", surface_area);
        Console.WriteLine("Volume of Sphere is : {0}", volume);
        Console.Read();
    }
}
Program Explanation

In this C# program, library function defined in <math.h> header file is used. We are reading the radius of the Sphere using ‘r’ variable. To compute the area and volume of the sphere the following formula is used

advertisement
advertisement

Surface_area = 4 * Pi * r * r,

Volume = 4 / 3 * Pi * r * r * r

where Pi = 22/7.

Note: Join free Sanfoundry classes at Telegram or Youtube
Runtime Test Cases
 
Enter the Radius of Sphere : 5
Surface Area of Sphere is : 314
Volume of Sphere is : 523.333333333333333

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.