Write a program in Java to calculate and display the hypotenuse of a Right- Angled Triangle by taking perpendicular and base as inputs.Draw the variable description table.
Answers
ur required CODE:-
// Java implementation of the approach
class GFG {
// Function to return the hypotenuse of the
// right angled triangle
static double findHypotenuse(double side1, double side2)
{
double h = Math.sqrt((side1 * side1) + (side2 * side2));
return h;
}
// Driver code
public static void main(String s[])
{
int side1 = 3, side2 = 4;
System.out.printf("%.2f", findHypotenuse(side1, side2));
}
}
Answer:
// C++ implementation of the approach
#include<bits/stdc++.h>
#include <iostream>
#include <iomanip>
using namespace std;
// Function to return the hypotenuse of the
// right angled triangle
double findHypotenuse(double side1, double side2)
{
double h = sqrt((side1 * side1) + (side2 * side2));
return h;
}
// Driver code
int main()
{
int side1 = 3, side2 = 4;
cout << fixed << showpoint;
cout << setprecision(2);
cout << findHypotenuse(side1, side2);
}
// This code is contributed by
// Surendra_Gangwar