Topic: Function
Write a function-‐oriented program to calculate the area of a circle. Use the
formula: A=πr2 where Pi(π) is equal to 3.1416 (approximately).
note: you can choose any looping statement.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace App
{
class Program
{
static double calculateAreaCircle(double radius)
{
const double PI = 3.1416;
return PI * radius * radius;
}
static void Main(string[] args)
{
Console.Write("Enter the radius of the circle: ");
double radius = double.Parse(Console.ReadLine());
Console.WriteLine("The area of a circle: {0}", calculateAreaCircle(radius));
Console.ReadLine();
}
}
}
Comments
Leave a comment