Q: Define 2 methods to compute volume and area of cylinder.
Get radius and length from user then call these methods and display results.
Formula: volume = π r2 h ; area = 2πrh+2πr2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Method_Ex_2
{
class Program
{
static void Main(string[] args)
{
double radius, length;
Console.Write("Enter radius: ");
double.TryParse(Console.ReadLine(), out radius);
Console.Write("\nEnter length: ");
double.TryParse(Console.ReadLine(), out length);
double volume = VolumeOfCylinder(radius, length);
double area = AreaOfCylinder(radius, length);
Console.WriteLine("\nVolume of cylinder: {0}", volume.ToString("f3"));
Console.WriteLine("\nArea of cylinder: {0}", area.ToString("f3"));
Console.ReadKey();
}
static double VolumeOfCylinder(double r, double h)
{
double v = Math.PI * r * r * h;
return v;
}
static double AreaOfCylinder(double r, double h)
{
double a = 2 * Math.PI * r * h;
return a;
}
}
}
No comments:
Post a Comment