Write a C# Console Application program that takes the radius of a circle as input and calculate the perimeter and area of the circle.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Program { static void Main(string[] args) { double r,perimeter, area; Console.Write("Please write the radius of your circle : "); r = Convert.ToDouble(Console.ReadLine()); perimeter = 2 * 3.14 * r; area = 3.14 * Math.Pow(r, 2); //area = 3.14 * r * r; Console.WriteLine("============================================="); Console.WriteLine("The perimeter of yor circle : {0}",perimeter); Console.WriteLine("The area of yor circle : {0}", area); Console.ReadKey(); } } |
Alternative: Writing with Tuple Syntax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | class Program { public static (double Area, double Perimeter) circleAreaPerimeter(double r) { double perimeter, area; perimeter = 2 * 3.14 * r; area = 3.14 * Math.Pow(r, 2); //area = 3.14 * r * r; return (area, perimeter); } static void Main(string[] args) { Console.Write("Please write the radius of your circle : "); double r = Convert.ToDouble(Console.ReadLine()); var result = circleAreaPerimeter(r); Console.WriteLine("============================================="); Console.WriteLine("The perimeter of yor circle : {0}", result.Perimeter); Console.WriteLine("The area of yor circle : {0}", result.Perimeter); Console.ReadLine(); } } |
When you run the program, the output will be: