斜邊是直角三角形的最長邊。當提供其他兩邊時,hypot()函數(shù)用于計算直角三角形的斜邊長。
double hypot(double p, double b);
在數(shù)學上h = √(p2+b2)等同于C語言編程h = hypot(p, b);。
hypot()函數(shù)在math.h 頭文件中定義 。
#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;
}輸出結(jié)果
hypot(5.00, 12.00) = 13.00