In: Computer Science
Write a program that prompts for and reads in the two side lengths of a right triangle (floating point numbers) and then calls a float-valued function, hypot1, that calculates and returns the length of the hypotenuse of the triangle. The program then displays the two side lengths and the hypotenuse length. Note: The hypot1 function returns the hypotenuse length – it does not display it; the function should not contain any cout nor cin statements. Math review: Recall that for any right triangle with side lengths a and b, and hypotenuse length c, a2+b2=c2. Here is an example of what output should look like from running your program (user input is shown in bold).
Enter the side lengths: 1.2 3.4
First side length = 1.2
Second side length = 3.4
Hypotenuse length = 3.60555
SOLUTION-
I have solve the problem in C++ code with comments and screenshot
for easy understanding :)
CODE-
//c++ code
#include <iostream>
#include <cmath>
using namespace std;
//function to calculate length of the hypotenuse of the
triangle.
float Hypot(float a, float b)
{
return sqrt(pow(a, 2) + pow(b, 2));
}
//main function
int main()
{
float a, b;
cout << "Enter the side lengths: ";
cin >> a >> b; //gets input from
user
cout << "First side length = " << a
<< endl;
cout << "Second side length = " << b
<< endl;
cout << "Hypotenuse length = " <<
Hypot(a, b) << endl; //call function and print
return 0;
}
SCREENSHOT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL
SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------