Basic Programming C# Examples

C# Program Calculate the perimeter,area of Circle

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:

  1. The using System; statement is a directive that tells the compiler to include the System namespace in the program.
  2. The namespace CircleCalculator defines a namespace that encapsulates the Program class.
  3. The class Program contains a Main method, which is the entry point of the application.
  4. The Main method starts by displaying a message asking the user to enter the radius of the circle.
  5. The user’s input is converted to a double using the Convert.ToDouble() method and stored in a variable called “radius”.
  6. The perimeter of the circle is calculated using the formula 2 * Math.PI * radius.
  7. The area of the circle is calculated using the formula Math.PI * Math.Pow(radius, 2).
  8. 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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X