C++ math hypot()
此函数查找两个数字的平方和的平方根。它代表斜边,用于查找直角三角形的斜边。
考虑三个数字x,y和z:
hypotenuse of a right angle triangle = √x2+y2 distance from origin in 3d space=√x2+y2+z2
语法
直角三角形的语法为:
double hypot(double x, double y);
float hypot(float x, float y);
long double hypot(long double x, long double y);
promoted hypot(type1 x, type2 y);
3d空间的语法为:
double hypot(double x, double y, double z);
float hypot(float x, float y, float z);
long double hypot(long double x, long double y, long double z);
promoted hypot(type1 x, type2 y, type3 z);
注意: 如果任何参数为long double类型,则返回类型将提升为long double。如果不是,则将返回类型提升为双精度。
参数
(x,y,z): x,y和z是float或
返回值
它返回两个数字平方和的立方根。
示例1
让我们看一个简单的示例。
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int x=2;
int y=3;
cout<<"sides of a right angled triangle are :";
cout<<x<<","<<y<<'\n';
cout<<"third side of a triangle is :"<<hypot(x,y);
return 0;
}
输出:
sides of a right angled triangle are :2,3
third side of a triangle is :3.60555