write a program that finds the hypotenuse of a right triangle, given lengths of
ID: 3658646 • Letter: W
Question
write a program that finds the hypotenuse of a right triangle, given lengths of its legs. Your program's dialog could go like this: This program asks you for the lengths of two legs of a right triangle, then computes the length of the hypotenuse using the Pythagorean theorem. Length of the first leg? 3 Length of the second leg? 4 Length of the hypotenuse: 5 Program end. This is a sample run: the 3 and 4 are sample inputs. Your program should produce, for example, 13 as the result of inputs 5 and 12, or 1.414213562373095048801688724 (more or less) for inputs 1 and 1. Assume that the user will enter positive values.Explanation / Answer
#include #include void main(void) { double side1, side2, sqrs1s2, hypoto; printf(" This program will calculate the hypotenuse of a right triangle. "); printf("Enter side one of the triangle: "); scanf("%d",&side1); ////gets side1 printf("Enter side two of the triangle: "); scanf("%d",&side2); ////gets side2 sqrs1s2 = (side1*side1 + side2*side2); hypoto = sqrt(sqrs1s2); ////uses squareroot to calculate hypotenuse printf("The lenth of the hypotenuse is: %d ", hypoto); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.