(1)abs()是对整数取绝对值, 而fabs()是对浮点数取绝对值。
(2)函数原型:
int abs(int x)double fabs(double x)
(3)头文件:
abs(): #include <stdlib.h>fabs(): #include <math.h>
c语言fabs是什么意思?
fabs函数是一个求绝对值的函数,求出x的绝对值,和数学上的概念相同,函数原型是extern float fabs(float x),用法是#include <math.h>。
fabs()函数的声明:double fabs(double x)。其中参数x 是浮点值,这个函数返回x的绝对值。代码示例如下:
int main (){int a, b;a = 1234;b = -344;printf("The absolute value of %d is %lf", a, fabs(a));printf("The absolute value of %d is %lf", b, fabs(b));return(0);}
编译和运行上面的程序,这将产生以下结果:
The absolute value of 1234 is 1234.000000The absolute value of -344 is 344.000000
以上就是我们小编整理了多篇后的内容,希望能够帮助到大家。
本文标题: c语言中abs()和fabs()的区别点整理
以上就上有关c语言中abs()和fabs()的区别点整理的相关介绍,要了解更多c语言,abs(),fabs()内容请登录学步园。