Latest web development tutorials

C library functions - fabs ()

C standard library - <math.h> C standard library - <math.h>

description

C library functionsdouble fabs (double x) Returns the absolute value of x.

statement

Here is () statement fabs function.

double fabs(double x)

parameter

  • x - floating-point value.

return value

This function returns the absolute value of x.

Examples

The following example demonstrates the fabs () function is used.

#include <stdio.h>
#include <math.h>

int main ()
{
   int a, b;
   a = 1234;
   b = -344;
  
   printf("%d 的绝对值是 %lf\n", a, fabs(a));
   printf("%d 的绝对值是 %lf\n", b, fabs(b));
   
   return(0);
}

Let's compile and run the above program, which will result in the following:

1234 的绝对值是 1234.000000
-344 的绝对值是 344.000000

C standard library - <math.h> C standard library - <math.h>