The hypot() function in Ruby returns the hypotenuse of a right-angled triangle from its length and base, which are sent as parameters.
The mathematical formula to calculate the hypotenuse from length and base is as follows:
hypotenuse = sqrt( length^2 + base^2 )
Figure 1 shows the visual representation of the hypot() function.
This function requires the
Mathmodule.
hypot(length, base)
This function requires length and base as parameters.
This function returns the hypotenuse of the right-angled triangle from its length and base, which are sent as parameters.
# the hypotenuse of right angled triangle# length=10# base=10print "The hypotenuse of triangle with length = 10 and base = 10: ",Math.hypot(10,10)," \n"# length=4# base=6print "The hypotenuse of triangle with length = 4 and base = 6: ",Math.hypot(4,6)," \n"