C Programming Tutorial
C Programming allows us to perform mathematical operations through the functions defined in
C Math Functions
In the C Programming Language, the fabs function returns the absolute value of a floating-point number.
Syntax
The syntax for the fabs function in the C Language is:
double fabs(double x);
Parameters or Arguments
The value to convert to an absolute value.
Returns
The fabs function returns the absolute value of a floating-point number represented by x.
Required Header
In the C Language, the required header for the fabs function is:
#include <math.h>
Applies To
In the C Language, the fabs function can be used in the following versions:
- ANSI/ISO 9899-1990
fabs Example
/* Example using fabs by c programming */
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
/* Define temporary variables */
double value;
double result;
/* Assign the value we will find the fabs of */
value = -2.1;
/* Calculate the absolute value of value */
result = fabs(value);
/* Display the result of the calculation */
printf("The Absolute Value of %f is %f\n", value, result);
return 0;
}
When compiled and run, this application will output:
The Absolute Value of -2.100000 is 2.100000
