C fabs Function

The C fabs function is a Math Function used to return the absolute positive number of a given value or a specified expression. The syntax of the fabs is

double fabs(double number);

C fabs Function Example

The math Function allows you to return the absolute positive number. In this math C 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;
}
C fabs Example

fabs Example 2

In this C Programming example, we allow users to enter their own values. Next, this program uses the 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 Absolute Value of %.2f = %.4f ", number, absValue);
  
    return 0;
}
 Please Enter any Numeric Value :  -23.456

 The Absolute Value of -23.46 = 23.4560

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.