头文件:#include <stdio.h>
hypot()用来求三角形的斜边长,其原型为:
double hypot(double x, double y);
在 C99 规范中,fypot() 的原型还可以是:
【参数】x 和 y 为 三角形的两条直角边。
【返回值】返回直角三角形的斜角边长,即 x2 + x2。
请看下面的代码:
- #include <stdio.h>
- #include <math.h>
- int main ()
- {
- double leg_x, leg_y, result;
- leg_x = 3;
- leg_y = 4;
- result = hypot (leg_x, leg_y);
- printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
- return 0;
- }
输出结果:3.000000, 4.000000 and 5.000000 form a right-angled triangle.