C++ <cstdlib> - abs() Function
The C++ <cstdlib> abs() function returns the absolute value (positive value) of the specified integral value. For example - absolute value of integral value x will be |x|.
Syntax
int abs (int x); long int abs (long int x);
int abs (int x); long int abs (long int x); long long int abs (long long int x);
Parameters
x |
Specify an integral value whose absolute value need to be determined. |
Return Value
Returns the absolute value (positive value) of integral argument.
Example:
The example below shows the usage of <cstdlib> abs() function.
#include <iostream> #include <cstdlib> using namespace std; int main (){ cout<<"abs(10) = "<<abs(10)<<"\n"; cout<<"abs(-10) = "<<abs(-10)<<"\n"; cout<<"abs(50) = "<<abs(-50)<<"\n"; cout<<"abs(-50) = "<<abs(50)<<"\n"; return 0; }
The output of the above code will be:
abs(10) = 10 abs(-10) = 10 abs(50) = 50 abs(-50) = 50
❮ C++ <cstdlib> Library