The Program in C# Sharp program that takes the radius of a circle as input and calculates the perimeter and area of the circle given below:
using System;
namespace CircleCalculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, enter the radius of the circle to find perimeter and area of circle:");
double radius = Convert.ToDouble(Console.ReadLine());
double perimeter = 2 * Math.PI * radius;
double area = Math.PI * Math.Pow(radius, 2);
Console.WriteLine("Well, the perimeter of the circle is: " + perimeter);
Console.WriteLine("Well,the area of the circle is: " + area);
}
}
}
Output:
Hello Codeauri Family, enter the radius of the circle to find perimeter and area of circle:7
Well, the perimeter of the circle is: 43.9822971502571Well,the area of the circle is: 153.9380400259
Pro-Tips💡
Here are the step by step execution of above program:
- The using System; statement is a directive that tells the compiler to include the System namespace in the program.
- The namespace CircleCalculator defines a namespace that encapsulates the Program class.
- The class Program contains a Main method, which is the entry point of the application.
- The Main method starts by displaying a message asking the user to enter the radius of the circle.
- The user’s input is converted to a double using the Convert.ToDouble() method and stored in a variable called “radius”.
- The perimeter of the circle is calculated using the formula 2 * Math.PI * radius.
- The area of the circle is calculated using the formula Math.PI * Math.Pow(radius, 2).
- Finally, the perimeter and area of the circle are displayed to the user using Console.WriteLine().
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.