Monday, 27 February 2017

Formula based program

Formula #2 (Perimeter and area of circle)

Enter radius: 5
Perimeter of circle: 31.4159265358979
Area of circle: 78.5398163397448

The program for the formula is written in C# programming language and will accept a number as radius. Based on the formula it will find out the perimeter and area of circle.
 
Formula based program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code these pattern.

Practical Implementation:

using System;

namespace patternProblem.Formula
{
    class Formula2     //area and perimeter of circle
    {
        static void Main(string[] args)
        {
            Console.Write("Enter radius: ");
            double radius = Convert.ToDouble(Console.ReadLine());
            double area = 0.0, perimeter=0.0;

            perimeter = 2* Math.PI * radius;
            area = Math.PI * (Math.Pow(radius, 2));

            Console.WriteLine("Perimeter of circle: {0}", perimeter);
            Console.WriteLine("Area of circle: {0}", area);

            Console.ReadKey();
        }
    }
}

Output:
The input radius here is 7. So, based on the circle formula. The output is shown below:

Enter radius: 7
Perimeter of circle: 43.9822971502571
Area of circle: 153.9380400259
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table – Formula based program

Previous – Formula based program #1

Next – Formula based program #3

Click imagination hunt to read latest blogs.


Keep learning and sharing...