C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

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   

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4