2025年4月11日 星期五 乙巳(蛇)年 正月十二 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > C语言

C语言hypot()函数:求直角三角形的斜边长

时间:12-30来源:作者:点击数:98

头文件:#include <stdio.h>

hypot()用来求三角形的斜边长,其原型为:
    double hypot(double x, double y);

在 C99 规范中,fypot() 的原型还可以是:

  • double hypot  (double x     , double y);
  • float hypotf (float x      , float y);
  • long double hypotl (long double x, long double y);

【参数】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.

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门