Calculates the absolute value of a long integer.
Include
<stdlib.h>
Prototype
long labs(long 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)
{
long i;
i = 123456;
printf("The absolute value of %7ld is %6ld\n",
i, labs(i));
i = -246834;
printf("The absolute value of %7ld is %6ld\n",
i, labs(i));
i = 0;
printf("The absolute value of %7ld is %6ld\n",
i, labs(i));
}
Example Output
The absolute value of 123456 is 123456
The absolute value of -246834 is 246834
The absolute value of 0 is 0