C hypot()

hypot() 函数原型

double hypot(double p, double b);

数学中的 h = √(p2+b2) 等价于 C 语言编程中的 h = hypot(p, b);


hypot() 函数定义在 math.h 头文件中。


示例:C hypot() 函数

#include <stdio.h>
#include <math.h>

int main()
{
    double p, b;
    double hypotenuse;

    p = 5.0;
    b = 12.0;

    hypotenuse = hypot(p, b);

    printf("hypot(%.2lf, %.2lf) = %.2lf", p, b, hypotenuse);

    return 0;
}

输出

hypot(5.00, 12.00) = 13.00

在我们结束之前,让我们来测试一下您对 C 语言数学 hypot() 的知识!您能解决以下挑战吗?

挑战

编写一个函数来计算直角三角形的斜边。

  • 提示:计算直角三角形斜边的公式是 {hypotenuse} = sqrt{{side1}^2 + {side2}^2}
  • 例如,输入 side1 = 3side2 = 4,返回值应为 5.00
你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战