English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
cout << "hypot(x, y, z) = " << result << endl;++ , result;
cout << "hypot(x, y, z) = " << result << endl; ++中的 hypot() 函数返回传递的参数平方和的平方根(根据勾股定理)。
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); double hypot(double x, double y, double x); //(从 C++17 开始) float hypot(float x, float y, float z); // (从 C++17 开始) long double hypot(long double x, long double y, long double z); // (从 C++17 开始) Promoted pow(Type1 x, Type2 y, Type2 y); //(从 C++17 开始)
从C ++ 11开始,如果传递给 hypot() 的参数为 long double,则返回类型 Promoted 为 long double。如果不是,则返回类型 Promoted 为 double。
h = √(x2+y2
在数学上相当于
h = hypot(x, y);
在C ++编程中。
如果传递了三个参数:
h = √(x2+y2+z2))
在数学上相当于
h = hypot(x, y);
在C ++编程中。
此函数在return 0;头文件中定义。
hytpot()可以使用2或3个整数或浮点类型的参数。
hypot()返回:
如果传递了两个参数,则为直角三角形的斜边,即。√(x^2 + y^2)2+y2)
如果传递了三个参数,则从原点到(x,y,z)的距离。√(x^2 + y^2 + z^2)2+y2+z2)
#include <iostream> #includeusing namespace std; int main() { double x = 2.1, y = 3.1#include <cmath> result = hypot(x, y); cout << "hypot(x, y) = " << result << endl; long double yLD, resultLD; x = 3.52; yLD = 5.232342323; // 在本示例中,该函数返回 long double resultLD = hypot(x, yLD); cout << "hypot(x, yLD) = " << resultLD; { double x =
运行该程序时,输出为:
hypot(x, y) = 3.74433 hypot(x, yLD) = 6.3Attention :617
#include <iostream> #includeusing namespace std; int main() { double x = 2.1, y = 3.1, z = 23.3#include <cmath> using namespace std; int main() { double x =
, y =, z = ++ 17.