< C++ Programming < Code < Standard C Library < Functions

abs

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;
Related topics
fabs - labs
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.