The longest side of a right-angled 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 )
Figure 1 shows the visual representation of the hypot()
function:
Note: We need to import
std.math
in our code to use thehypot()
function. We can import it like this:import std.math
hypot(length, base)
This function requires length
and base
as parameters.
This function returns the hypotenuse of the right-angled triangle. The triangle’s length and base are passed as parameters.
The code below shows the use of the hypot()
function in D:
import core.stdc.stdio;import std.stdio;//header required for functionimport std.math;int main(){//positive: length positive: basewriteln ("The value of hypot(10,10) : ",hypot(10,10));//positive: length negative: basewriteln ("The value of hypot(0.25,-2) : ",hypot(0.25,-2));//negative: length positive: basewriteln ("The value of hypot(-10,2) : ",hypot(-10,2));//negative: length negative: basewriteln ("The value of hypot(-0.5,-1) : ",hypot(-0.5,-1));// few exceptional outputswriteln ("The value of hypot(real.infinity,real.infinity) : ",hypot(real.infinity,real.infinity));writeln ("The value of hypot(-real.infinity,-real.infinity) : ",hypot(-real.infinity,-real.infinity));writeln ("The value of hypot(real.nan,real.nan) : ",hypot(real.nan,real.nan));writeln ("The value of hypot(-real.nan,-real.nan) : ",hypot(-real.nan,-real.nan));return 0;}
std.math
library.hypot()
.