Calculate Area of Different Shapes in C# Using Method.
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP_Methods_paractise
{
class Program
{
public static void circle(double rad)
{
double area = Math.PI * Math.Pow(rad, 2);
Console.WriteLine("The Area Of Circle Is:{0}",area);
}
public static void Square(double Len)
{
double area = Math.Pow(Len, 2);
Console.WriteLine("The Area Of Square Is:{0}", area);
}
public static void Rectangle(double reclen,double wid)
{
double area = reclen * wid;
Console.WriteLine("The Area Of Rectangle Is:{0}", area);
}
public static void Tringle(double tribas,double trihei)
{
double area = 0.5*(tribas * trihei);
Console.WriteLine("The Area Of Triangle Is:{0}", area);
}
static void Main(string[] args)
{
string ans;
do
{
Console.WriteLine("Which Shape Do You Want To Calculate It Area");
Console.WriteLine("1.Circle");
Console.WriteLine("2.Square");
Console.WriteLine("3.Rectangle");
Console.WriteLine("4.Trianfle");
string op = Console.ReadLine();
if (op == "1")
{
Console.WriteLine("Enter Radius of circle");
double radius = double.Parse(Console.ReadLine());
Program.circle(radius);
}
else if (op == "2")
{
Console.WriteLine("Enter Length of Square");
double Length = double.Parse(Console.ReadLine());
Program.Square(Length);
}
else if (op == "3")
{
Console.WriteLine("Enter Length of Rectangle");
double Length = double.Parse(Console.ReadLine());
Console.WriteLine("Enter Width of Rectangle");
double width = double.Parse(Console.ReadLine());
Program.Rectangle(Length, width);
}
else if (op == "4")
{
Console.WriteLine("Enter Base of Triangle");
double Base = double.Parse(Console.ReadLine());
Console.WriteLine("Enter Height of Triangle");
double height = double.Parse(Console.ReadLine());
Program.Tringle(Base, height);
}
else
{
Console.WriteLine("Invalid Choice");
}
Console.WriteLine("Do you want to Perform More Operations(yes,no)");
ans = Console.ReadLine().ToLower();
} while (ans=="yes");
}
}
}
Comments
Post a Comment