hypot()函数以及C ++中的示例
C++hypot()函数
hypot()函数是cmath标头的库函数,用于查找给定数字的斜边,接受两个数字并返回斜边的计算结果,即sqrt(x*x+y*y)。
hypot()函数语法:
hypot(x, y);
参数:x,y–要计算的斜边数(或sqrt(x*x+y*y))
返回值:double-它返回double值,该值是表达式sqrt(x*x+y*y)的结果。
示例
Input:
float x = 10.23;
float y = 2.3;
Function call:
hypot(x, y);
Output:
10.4854C++代码演示hypot()函数示例
//示例
//hypot()功能
#include <iostream>
#include <cmath>
using namespace std;
//主代码部分
int main(){
float x = 10.23;
float y = 2.3;
//计算斜边
float result = hypot(x, y);
cout<<"hypotenuse of "<<x<<" and "<<y<<" is = "<<result;
cout<<endl;
//使用sqrt()功能
result = sqrt((x*x + y*y));
cout<<"hypotenuse of "<<x<<" and "<<y<<" is = "<<result;
cout<<endl;
return 0;
}输出结果
hypotenuse of 10.23 and 2.3 is = 10.4854 hypotenuse of 10.23 and 2.3 is = 10.4854
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短