A right triangle is a triangle that has a 90-degree angle. The side opposite the
ID: 3634437 • Letter: A
Question
A right triangle is a triangle that has a 90-degree angle. The side opposite the 90-degree angle iscalled the hypotenuse and the sides adjacent to the 90-degree angle are called legs. Consider a right
triangle with sides a; b; c, where a; b are the legs and c is the hypotenuse. The following equation
holds
c2 = a2 + b2:
Let be the angle (in degree) between a; c, and be the angle (in degree) between b; c. Then we
have
=
180
arctan(b=a); =
180
arctan(a=b); + = 90:
Write a program triangle.c that prompts the user for the double-precision1 legs of a right triangle
and prints the hypotenuse and the smallest angle (in degree) of that triangle with 1-decimal point
precision.
Include a function void Compute(double *cp, double *anglep, double a, double b) that
computes the hypotenuse and the smallest angle of the right triangle with legs a; b, and stores
them respectively in the variables pointed by cp and anglep.
Sample runs:
(~)$ a.out
Legs: 3.0 4.0
Hypotenuse: 5.0
Smallest angle: 36.9 degree
(~)$ a.out
Legs: 5 10
Hypotenuse: 11.2
Smallest angle: 26.6 degree
(~)$ a.out
Legs: 2.5 2.5
Hypotenuse: 3.5
Smallest angle: 45.0 degree
(~)$
Explanation / Answer
Dear, Program : /*This program computes the Hypotenuse and smallest angle in a right triangle*/ /*header files*/ /*needed for I/O operations*/ #include /*needed for math functions*/ #include /*constant declaration*/ #define pi 3.14159265 /*function to compute angle and hypotenuse*/ void Compute(double *cp, double *anglep, double a, double b) { double alpha, beta; /*calculating hypotenuse */ *cp=sqrt((a*a)+(b*b)); /*calculating angles */ alpha = (180/pi)*atan(b/a); beta = (180/pi)*atan(a/b); /*condition to find the smallest angle */ if (alpha > beta) *anglep = beta; else if(alphaRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.