Finding Pythagoras Theorem in c# Using Switch-Case.
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP__TH__task
{
class Program
{
static void Main(string[] args)
{ double p, h, b;
string choice;
Console.WriteLine("Enter what you want to find:");
Console.WriteLine("h is for Hypotenius ");
Console.WriteLine("b is for base");
Console.WriteLine("p is for perpendicular");
choice = Convert.ToString(Console.ReadLine());
switch (choice)
{
case "h":
Console.WriteLine("Enter Value of Perpendicular:");
p = double.Parse(Console.ReadLine());
Console.WriteLine("Enter Value of Base:");
b = double.Parse(Console.ReadLine());
h = Math.Sqrt(Math.Pow(p, 2) + Math.Pow(b, 2));
Console.WriteLine("The Final Value Of Hypotenius:{0:F2}", h);
break;
case "b":
Console.WriteLine("Enter Value of Perpendicular:");
p = double.Parse(Console.ReadLine());
Console.WriteLine("Enter Value of Hypotenius:");
h = double.Parse(Console.ReadLine());
b = Math.Sqrt(Math.Pow(p, 2) + Math.Pow(h, 2));
Console.WriteLine("The Final Value Of Base:{0:F2}", b);
break;
case "p":
Console.WriteLine("Enter Value of Base:");
b = double.Parse(Console.ReadLine());
Console.WriteLine("Enter Value of Hypotenius:");
h = double.Parse(Console.ReadLine());
p = Math.Sqrt(Math.Pow(b, 2) + Math.Pow(h, 2));
Console.WriteLine("The Final Value Of Perpendicular:{0:F2}",p);
break;
default:
Console.WriteLine("Invalid Term");
break;
}
}
}
}
Comments
Post a Comment