C hypot 函数

hypot 函数是 C 编程中的一个数学函数,用于计算给定两边的三角函数斜边值。hypot 的语法如下所示。

double hypot(double number);

斜边 = 两边平方和的平方根(指定的参数)。

hypot 函数示例

math hypot 函数允许您查找给定边的斜边值。在此 程序 中,我们将查找斜边并显示输出。

/* Example for HYPOT */

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

int main()
{
printf("\n The Hypotenuse Value of 10 & 0 = %.4f ", hypot(10, 0));
printf("\n The Hypotenuse Value of 0 & -5 = %.4f ", hypot(0, -5));

printf("\n The Hypotenuse Value of 5 & -2 = %.4f ", hypot(5, -2));
printf("\n The Hypotenuse Value of -2 & 10 = %.4f ", hypot(-2, 10));

printf("\n The Hypotenuse Value of 10 & 12 = %.4f ", hypot(10, 12));
printf("\n The Hypotenuse Value of 5 & 20 = %.4f ", hypot(5, 20));

return 0;
}
 The Hypotenuse Value of 10 & 0  = 10.0000 
 The Hypotenuse Value of 0 & -5  = 5.0000 
 The Hypotenuse Value of 5 & -2  = 5.3852 
 The Hypotenuse Value of -2 & 10 = 10.1980 
 The Hypotenuse Value of 10 & 12 = 15.6205 
 The Hypotenuse Value of 5 & 20  = 20.6155

math hypot 示例 2

在此 C 编程 示例中,我们允许用户输入三角形的两条边。接下来,我们使用 math hypot 函数来查找用户给定边的斜边。

/* Example for HYPOT */

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

int main()
{
int side1, side2;
float hValue;

printf(" Please Enter the First and Second Side : ");
scanf("%d%d", &side1, &side2);

hValue = hypot(side1, side2);

printf("\n The Hypotenuse Value of %d & %d = %.4f ", side1, side2, hValue);

return 0;
}
C hypot Function Example