Both abs and fabs computes absolute value of the given value.

**abs():**

Used for integer values computing. Always returns a positive value.

Synopsis for abs:

**#include <stdlib.h>
int abs(int x);**

Computes the absolute value of x. Returns x if x is positive or negative.

For eg., the following code will output 50.

printf("%i\n", abs(-50));

**fabs():**

Used for floating numbers computing. Its slower and works only on floating type numbers.

Synopsis for fabs:

**#include <math.h>
double fabs(double x);**

Computes the absolute value of floating number x. Returns x if x is positive or negative.

For eg., the following code will output 50.

printf("%.2f\n", fabs(-50.00));

0 votes

...