Question
Programming C Next you will need #include and #include . You will also need the constant PI which will be defined as 3.14159 Now write
Programming C
Next you will need #include
Now write the prototypes for two functions:
- One is called hypotenuse which returns a double and takes as arguments two doubles for the two sides of a right triangle. (It will return the length of the hypotenuse of that triangle.
- The other is called angle, it will take a side and a hypotenuse return the angle opposite that side. The return type of this one will also be a double.
Now write a main with variables for the two sides, the hypotenuse, and the two angles. (Yes, a triangle has three angles, but one of them is 90 because this is a right triangle.) Begin by asking the user for the two sides. Then call your function to compute the hypotenuse. This information is then passed to the function that calculates the angle. The output of the result is done in the main, not in the functions. The functions simply make calculations and return the result of those calculations.
Under the main write the definition of the two functions:
- hypotenuse will use the Pythagorean formula, c = square_root(a2 + b2) [use the sqrt function from math.h]
- angle will compute one of the angles (not the 90 angle). For this we will use the fact that the sine of an angle = the opposite-side/hypotenuse. If we send this value to the math.h function asin we find out a value for the angle. BUT the value is returned in radians, not degrees. To convert this to degrees we multiply it 180 and divide it by PI
There are two ways to calculate the other angle. I will leave you to figure them out. (Hint: One of them uses the fact that the sum of the angles of any triangle is 180.)
Output should be formatted to two decimal places.
Sample interaction:
Please enter the two sides of your triangle.
45
60
The hypotenuse of your triangle is 75.00
The two angles of your triangle are 36.87 degrees and 53.13 degrees.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started