Example: perimeter and area of a circle

Let us write a program that calculates a circle area and a perimeter by reading its radius r .

Formulas:

  • Area = π * r * r
  • Perimeter = 2 * π * r
  • π ≈ 3.14159265358979323846…
Console.Write("Enter circle radius. r = ");
var r = double.Parse(Console.ReadLine());
Console.WriteLine("Area = " + Math.PI * r * r); 
  // Math.PI - built in constant for π in C#
Console.WriteLine("Perimeter = " + 2 * Math.PI * r);

Let us test the program with radius r = 10:

Testing in the Judge System

Test your solution here:https://judge.softuni.bg/Contests/Practice/Index/504#5.

results matching ""

    No results matching ""