The longest side of a right-angle triangle, and the side opposite to the right angle, is known as the hypotenuse in geometry.
The mathematical formula to calculate the hypotenuse’s length is known as the Pythagorean theorem and is as follows:
hypotenuse = sqrt( length^2 + base^2 )
The following figure shows the visual representation of the hypot()
function:
Note: We need to import
Foundation
in our code to use thehypot()
function. We can import it usingimport Foundation
.
hypot(length, base)
This function requires the length
and base
as parameters.
This function returns the hypotenuse of the right-angle triangle. The triangle’s length and base are passed as parameters.
The code below shows the use of the hypot()
function in Swift:
import Swiftimport Foundation//positive: length positive: baseprint ("The value of hypot(2.0,3.0) : ",hypot(2.0,3.0));//positive: length negative: baseprint ("The value of hypot(0.25,-2.0) : ",hypot(0.25,-2.0));//negative: length positive: baseprint ("The value of hypot(-10.0,2.0) : ",hypot(-10.0,2.0));//negative: length negative: baseprint ("The value of hypot(-0.5,-1.0) : ",hypot(-0.5,-1.0));
Foundation
header required for hypot()
function.hypot()
.hypot()
.hypot()
.hypot()
.