hypot - C math.h

C examples for math.h:hypot

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the hypotenuse of a right-angled triangle whose legs are x and y.

Prototype

long double hypotl (long double x, long double y);
long double hypot (long double x, long double y);
     double hypot  (double x     , double y);
      float hypotf (float x      , float y);
      float hypot (float x      , float y);
     double hypot (Type1 x      , Type2 y);       

Parameters

Parameter Description
x Floating point values corresponding to the legs of a right-angled triangle.
y Floating point values corresponding to the legs of a right-angled triangle.

Return Value

The square root of (x^2 + y^2).

Example

Demo Code

#include <stdio.h>
#include <math.h> /* hypot */

int main ()/*w w w .j  a va  2s.c o m*/
{
  
  double leg_x = 3;
  double leg_y = 4;
  double result = hypot (leg_x, leg_y);
  printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
  return 0;
}

Related Tutorials