此函数查找两个数字的平方和的平方根。它代表斜边,用于查找直角三角形的斜边。
直角三角形的斜边=√x2+ y2在3d空间中距原点的距离=√x2+ y2 + z2
hypot - 语法
直角三角形的语法为:
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);
Note:如果任何参数为long double类型,则将返回类型提升为long double。如果不是,则将返回类型提升为双精度。
hypot - 参数
(x,y,z) : x,y和z是float或整数类型的值。
hypot - 返回值
它返回两个数字的平方和的立方根。
hypot - 例子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<<
;
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