w3resource

C fabs() function

C fabs() function - Absolute value function

Syntax:

double fabs(double x)

The fabs() function is used to calculate the absolute value of the floating-point argument x.

Parameters:

Name Description Required /Optional
x Floating-point value. Required

Return value from fabs()

  • This function returns the absolute value of x.

Example: fabs() function

The following example shows the usage of fabs() function.


#include <math.h>
#include <stdio.h>
 
int main(void)
{
   double x, y;
 
   x = -7.837345;
   y = fabs(x); 
   printf("fabs( %lf ) = %lf\n", x, y);
   x = -12.22;
   y = fabs(x); 
   printf("\nfabs( %lf ) = %lf\n", x, y);
   x = 34.890;
   y = fabs(x); 
   printf("\nfabs( %lf ) = %lf\n", x, y);

} 

Output:

fabs( -7.837345 ) = 7.837345

fabs( -12.220000 ) = 12.220000

fabs( 34.890000 ) = 34.890000

C Programming Code Editor:

Previous C Programming: C ceil()
Next C Programming: C floor()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming/math/c-fabs.php