Calculates the absolute value.
Include
<stdlib.h>
Prototype
int abs(int i);
Argument
i
Return Value
Returns the absolute value of i
.
Remarks
A negative number is returned as positive; a positive number is unchanged.
Example
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
i = 12;
printf("The absolute value of %d is %d\n", i, abs(i));
i = -2;
printf("The absolute value of %d is %d\n", i, abs(i));
i = 0;
printf("The absolute value of %d is %d\n", i, abs(i));
}
Example Output
The absolute value of 12 is 12
The absolute value of -2 is 2
The absolute value of 0 is 0