I need to write a program that reads the radius r of a circle and prints its area formatted with 2 digits after the decimal point. Examples:

 r area OUTPUT: 2 12.5663706143592 12.57 3.5 38.484510006475 38.48

asked in C# category
edited

Formula for calculating the area of a circle:

and the code:

```using System;

class CircleArea
{
static void Main()
// Area of a circle: A=πr2
{
Console.WriteLine("Please write the radius of your circle and hit Enter afterwards: ");
double pi = Math.PI;
double area = pi * (radius * radius);
Console.WriteLine("The Area (A=πr2) of your circle is: {0:0.00}", area);
}
}```

For formatting 2 digits after the decimal point I used: {0:0.00}

but you can also use {0:0.F2}

edited by user golearnweb

Here's my code:

```using System;

class CircleArea
{
static void Main()
{
double area = Math.PI * (radius * radius);

Console.WriteLine("Area = {0:F2}", area);
}
}```

edited by user golearnweb

...and mine:

```using System;

public class Program
{
public static void Main()
{
double r = double.Parse(Console.ReadLine());

Console.WriteLine("The area of circle is: {0:F2}", Math.PI * r * r);
}
}```