C ++ hypot función () : Aquí, vamos a aprender acerca de la función hypot () con el ejemplo de cabecera cmath en C ++ Programming Language?
C ++ hypot () función
hypot () función es una función de biblioteca de cmath cabecera, se utiliza para encontrar la hipotenusa de los números dados, acepta dos números y devuelve el resultado calculado de hipotenusa es decir sqrt (x * x + y * y) .
Sintaxis de hypot () Función:
hypot(x, y);
Parámetro (s): x, y – hipotenusa números para calcular (o sqrt (x * x + y * y) )
Return valor: double – devuelve valor double que es el resultado de la expresión sqrt (x * x + y * y) .
Ejemplo:
Input:
float x = 10.23;
float y = 2.3;
Function call:
hypot(x, y);
Output:
10.4854
C ++ código para demostrar el ejemplo de la función hypot ()
// C++ code to demonstrate the example of
// hypot() function
#include <iostream>
#include <cmath>
using namespace std;
// main code section
int main()
{
float x = 10.23;
float y = 2.3;
// calculate the hypotenuse
float result = hypot(x, y);
cout<<"hypotenuse of "<<x<<" and "<<y<<" is = "<<result;
cout<<endl;
//using sqrt() function
result = sqrt((x*x + y*y));
cout<<"hypotenuse of "<<x<<" and "<<y<<" is = "<<result;
cout<<endl;
return 0;
}
salida
hypotenuse of 10.23 and 2.3 is = 10.4854
hypotenuse of 10.23 and 2.3 is = 10.4854