Question #284778

use method to create a program that will display the area of circle based on the radius inputted by the user.It should contain the following method:input_radius,comp_area and display_result.You may use the formula: A=r², where r=3.1416

Expert's answer

using System;
namespace Area_of_a_circle
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            Console.Write("Enter a radius: ");
            double radius = double.Parse(Console.ReadLine());
            Input_Radius(radius);
            Comp_Area(Input_Radius(radius));
            Display_Result(Comp_Area(Input_Radius(radius)));
            Console.ReadLine();
        }
        static double Input_Radius(double radius)  // Method Input_Radius
        {
            return radius;
        }

        static double Comp_Area(double r)  // Method Comp_Area
        {
            double p = 3.14;  // const pi
            double s = p * Math.Pow(r, 2); // area
            return s;
        }

        static void Display_Result(double s)  // Method Display_Result
        {
            Console.WriteLine($"Area of a circle based on radius = {s}");
        }
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS