The hypotenuse length of a right triangle. A right triangle has an interior angle of 90 degrees - a right angle. We typically label the two sides or legs adjacent to the right angle a and b, and the side opposite the right angle, the hypotenuse, c.
Test Cases
The well-known property of right triangles, that the side lengths form the ratio 3:4:5, provides our first test case. (Some researchers speculate that the Egyptians used this ratio to help build the ancient pyramids without using modern surveying tools.) We could use the ratio to generate other test cases (e.g., 9:12:15), but it's best to have a different, more general test case. So, pick two arbitrary values for the legs and use a calculator to calculate the hypotenuse, creating a second test case.
a
b
c
Case 1
3
4
5
Case 2
4.5
6.25
7.70146
Caution
Mathematically and programmatically, taking the square root of a negative value is an illegal operation. But this problem will never occur with the following program because it squares both a and b, yielding non-negative values. If the sqrt function argument is negative, the returned (and printed) value looks rather strange and indicates an error condition: -1.#IND