Programming Course in C# ¡Free!

Sphere, float

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

Calculate the surface and volume of a sphere, given its radius (surface = 4 * pi * radius squared; volume = 4/3 * pi * radius cubed).

Hint: for "float" numbers, you must use Convert.ToSingle(...)


Output



Solution


using System;
public class Sphere
{
public static void Main()
{   
float radius;
float pi = 3.1415926535f;

Console.Write("Radius? ");
radius = Convert.ToSingle(Console.ReadLine());

Console.WriteLine( 4 * pi * (radius * radius) );

Console.WriteLine( 4/3 * pi * (radius * radius * radius));
}
}