Calculate Area of Circle , Rectangle, Triangle, square in switch-case in c#.
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Switch_Case_practise
{
class Program
{
static void Main(string[] args)
{
double area=0;
Console.WriteLine("Choose Shape To Calculate It Area:");
Console.WriteLine("1.Circle");
Console.WriteLine("2.Square");
Console.WriteLine("3.Ractangle");
Console.WriteLine("4.Triangle");
int choise = int.Parse(Console.ReadLine());
switch (choise)
{
case 1:
Console.WriteLine("Enter Radius Of Circle:");
double radius = Convert.ToDouble(Console.ReadLine());
area = Math.PI * Math.Pow(radius, 2);
Console.WriteLine("Area of Circle: {0}",area);
break;
case 2:
Console.WriteLine("Enter Length Of Square");
double length = double.Parse(Console.ReadLine());
area = Math.Pow(length, 2);
Console.WriteLine("Area of Square {0}",area);
break;
case 3:
Console.WriteLine("Enter Length of Rectangle:");
double lengthrec = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Width Of Rectangle:");
double width = Convert.ToDouble(Console.ReadLine());
area = lengthrec * width;
Console.WriteLine("Area of Rectangle is {0}",area);
break;
case 4:
Console.WriteLine("Enter Base of Triangle:");
double tribase = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Heigth Of Triangle:");
double heigth = Convert.ToDouble(Console.ReadLine());
area = 0.5*(tribase*heigth);
Console.WriteLine("Area of Triangle is {0}", area);
break;
default:
Console.WriteLine("Invalid Option");
break;
}
Comments
Post a Comment