fabs() in C++


The C or C++ library function double fabs(double x) returns the absolute value of x. x − This is the floating point value. This function returns the absolute value of x. Following is the declaration for fabs() function.

double fabs(double x)

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

Example

 Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main () {
   int a, b;
   a = 1234;
   b = -344;
   cout << "The absolute value of " << a << " is " << fabs(a) <<
   endl;
      cout << "The absolute value of " << b << " is " << fabs(b) <<
   endl;
      return(0);
}

Output

The absolute value of 1234 is 1234
The absolute value of -344 is 344

Updated on: 30-Jul-2019

458 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements