hypot(x,y)函数详解

首页 / C++入门教程 / hypot(x,y)函数详解

此函数查找两个数字的平方和的平方根。它代表斜边,用于查找直角三角形的斜边。

直角三角形的斜边=√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空间的语法为:

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-hypot-function.html

来源:LearnFk无涯教程网

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<<'\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   

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

从0开始学架构 -〔李运华〕

数据分析实战45讲 -〔陈旸〕

许式伟的架构课 -〔许式伟〕

从0打造音视频直播系统 -〔李超〕

DDD实战课 -〔欧创新〕

说透敏捷 -〔宋宁〕

视觉笔记入门课 -〔高伟〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

爆款文案修炼手册 -〔乐剑峰〕

好记忆不如烂笔头。留下您的足迹吧 :)