C++ hypot()

Last Updated On Thursday 21st Apr 2022

hypot function

The C++ hypot() function returns the square root of sum of square of arguments passed. It is defined in <cmath> header file.

Syntax

	hypot(double x, double y);
	

Parameters

The hypot() function takes a two argument.

  • x , y – Floating point values corresponding to the legs of a right-angled triangle for which the hypotenuse is computed.

Return value

Returns the square root of x & y.

std hypot

hypot() prototype [As of C++ 11 standard]

	double hypot(double x, double y);
float hypot(float x, float y);
long double hypot(long double x, long double y);
Promoted pow(Type1 x, Type2 y);
	

hypot math

Example : C++ hypot()

	#include <stdio.h>
#include <math.h>

int main () {
  double x, y, result;
  x = 3;
  y = 4;
  result = hypot (x, y);
  printf ("%f, %f and %f form a right-angled triangle.\n",x,y,result);
  return 0;
}
	

Output

	3.000000, 4.000000 and 5.000000 form a right-angled triangle.