C <math.h> - fabs() Function
The C <math.h> fabs() function returns the absolute value (positive value) of the specified number. For example - absolute value of x will be |x|.
Syntax
double fabs (double x); float fabsf (float x); long double fabsl (long double x);
Parameters
x |
Specify a number whose absolute value need to be determined. |
Return Value
Returns the absolute value (positive value) of the argument.
Example:
In the example below, fabs() function returns the absolute value (positive value) of the specified number.
#include <stdio.h> #include <math.h> int main (){ printf("%lf\n", fabs(10)); printf("%lf\n", fabs(-10)); printf("%lf\n", fabs(-5.45)); printf("%lf\n", fabs(-5.55)); return 0; }
The output of the above code will be:
10.000000 10.000000 5.450000 5.550000
❮ C <math.h> Library