Syntax:
#include <cstdlib> int abs( int num );
The abs() function returns the absolute value of num. For example:
int magic_number = 10; cout << "Enter a guess: "; cin >> x; cout << "Your guess was " << abs( magic_number - x ) << " away from the magic number." << endl;
C++ also provides the following overloaded forms:
#include <cstdlib> long abs( long num ); // same as labs() #include <cmath> // the following are synonyms for fabs() float abs( float num ); double abs( double num ); long double abs( long double num );