If a right triangle has sides of length A, B and C and if C is the largest, then it is called the “hypotenuse” and its length is the square root of the sum of the squares of the lengths of the shorter sides (A and B). Assume that variables a and b have been declared as doubles and that a and b contain the lengths of the shorter sides of a right triangle: write an expression for the length of the hypotenuse.

LANGUAGE: C++

CHALLENGE:

If a right triangle has sides of length A, B and C and if C is the largest, then it is called the “hypotenuse” and its length is the square root of the sum of the squares of the lengths of the shorter sides (A and B). Assume that variables a and b have been declared as doubles and that a and b contain the lengths of the shorter sides of a right triangle: write an expression for the length of the hypotenuse.

SOLUTION:


sqrt (a*a + b*b)