Create a C application to calculate the length of the hypote
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
Solution
using System;
class Pythagoras
{
public static void Main()
{
double side1;
double side2;
Console.WriteLine(\"Enter side1: \"); // read side1
side1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(\"Enter side2: \"); // read side 2
side2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(\"Hypotense: {0}\", calculateHypotense(side1, side2));
}
// function to determine hypotanse
static double calculateHypotense(double side1, double side2)
{
return Math.Sqrt(side1 * side1 + side2 * side2);
}
}
//output:
// Enter side1:3.0
//Enter side2:4.0
//Hypotense: 5.0
