The C fabs function is a Math Function useful to return the absolute positive number of a given value or a specified expression. The syntax of the fabs is as shown below.
double fabs(double number);
C fabs Function Example
The math Function allows you to return the absolute positive number. In this math fabs program, we will find the absolute positive number of different values and display the output.
#include <stdio.h> #include <math.h> int main() { printf("\n The Absolute Value of 0 = %.4f ", fabs(0)); printf("\n The Absolute Value of 1 = %.4f ", fabs(1)); printf("\n The Absolute Value of 152 = %.4f ", fabs(152)); printf("\n The Absolute Value of 400.36 = %.4f ", fabs(400.36)); printf("\n The Absolute Value of -27.32 = %.4f ", fabs(-27.32)); printf("\n The Absolute Value of -90 = %.4f ", fabs(-90)); return 0; }
fabs Example 2
In this C Programming example, we allow users to enter their own values. Next, this program uses the math fabs function to find the absolute positive number of the user-given value.
#include <stdio.h>
#include <math.h>
int main()
{
float number, absValue;
printf(" Please Enter any Numeric Value : ");
scanf("%f", &number);
absValue = fabs(number);
printf("\n The Result of %.2f = %.4f ", number, absValue);
return 0;
}
Please Enter any Numeric Value : -23.456
The Result of -23.46 = 23.4560