Create a C# application to calculate the length of the hypotenuse of a right-ang
ID: 673665 • Letter: C
Question
Create a C# application to calculate the length of the hypotenuse of a right-angle triangle. This application has two methods: Main and Hypotenuse, both of them static. In Main, the user is asked to enter the lengths of the other two sides. Main then calls Hypotenuse and passes the lengths as arguments. Hypotenuse calculates and returns the length of the hypotenuse, which is equal to the square root of the sum of the square of the other two sides. For example, if the lengths of the other two sides are 3.0 and 4.0, the length of the hypotenuse is the square root of (3.0 * 3.0 + 4.0 * 4.0). The Math class in .NET Framework Class Library has a static method Sqrt, which calculates the square root of a value. Display the length of the hypotenuse in the console window.
Explanation / Answer
using System;
public class Test{
public static double hypo(int b,int p){
return Math.Sqrt(b*b + p*p);
}
public static void Main(){
int b,p;
Console.WriteLine("Enter the value of Base : ");
b = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the value of Perpendicular : ");
p = Int32.Parse(Console.ReadLine());
Console.WriteLine("Hypotenous is "+hypo(b,p));
}
}
use this link http://ideone.com/fy8n13 for output