Home >>C Math Functions >C math fabs() function
The C math fabs() function is used to return the absolute value of any given number x. It takes a single argument (in double) and returns the absolute value of that number (also in double). This function is defined in <math.h> header file.
Syntax:double fabs(double x)
x It is the floating point value.
Here is an example of fabs() function:
#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);
}
#include <stdio.h>
#include <math.h>
int main ()
{
int a, b;
a = 365.83;
b = -34.313;
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);
}