C语言 <math.h> fabs 函数 描述 C库函数double fabs(double x))返回x的绝对值。 声明 以下是fabs函数的声明。 double fabs(double x) 复制 参数 x - 这是浮点值。 返回值 此函数返回x的绝对值。 示例 以下示例显示fabs函数的用法- #include <stdio.h> #include <math.h> int main () { int a, b; a = 1234; b = -344; printf("The absolute value of %d is %lf\n", a, fabs(a)); printf("The absolute value of %d is %lf\n", b, fabs(b)); return(0); } 复制尝试一下 让我们编译并运行上面的程序,它将产生以下结果- The absolute value of 1234 is 1234.000000 The absolute value of -344 is 344.000000 复制 返回math.h头文件