abs
integer absolute value function
INTERFACE
#include <stdlib.h>
int abs ( int j )
DESCRIPTION
The abs function computes the absolute value of the integer j, denoted by $|j|$
and defined through:
$$|j| :=
\left\{
\begin{array}{ll}
j, & j \geq 0, \\
-j, & j < 0.
\end{array}
\right.$$
(1)
Example 1
Workings
\code #include <stdio.h> #include <stdlib.h> int main() { int a = -127; printf("|a| = %d
", abs(a)); return 0; } \endcode
Solution
Output:
|a| = 127RETURN VALUES
The abs function returns the absolute value.
SEE ALSO
BUGS
The absolute value of the most negative integer remains negative.