C++ hypot()函数,勾股定理

hypot()函数

C++的hyplot()函数,可以用于计算两个参数的平方和,并开平方根,也就是直角三角形的勾股定理的公式,斜边等于两直角边的平方的和再开根号。

提示:使用hypot()函数时,需先include <cmath>头文件!

C++ hypot()函数语法

double hypot( a, b )

hypot()参数

参数描述
a、bdouble类型值。
hyplot()返回值

双精度浮点数。

hypot()函数实例代码

直角三角形的两个直角边为6和8,斜边可以根据勾股定理计算得到为10,下面将通过C++的hypot()函数来计算6和8的平方和的平方根:

#include <iostream>
#include <cmath>
using namespace std;


int main(){

    double x = hypot(6,8);
    cout << x;
    
}

免责声明:内容仅供参考,不保证正确性!


全栈后端 / C++教程 :
















Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.