Chapter Contents

Previous

Next
labs

labs



Integer Conversion: Absolute Value

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <stdlib.h>

long int labs(long int j);


DESCRIPTION

labs returns the absolute value of a long int .


RETURN VALUE

labs returns the absolute value of its argument. Both the result and the argument are of long int type.


IMPLEMENTATION

labs is implemented as a macro that invokes the built-in abs function.


EXAMPLE

#include <stdio.h>
#include <stdlib.h>

main()
{
   long int a, c;  /* The variable, a, can have a negative value. */
   int b;

   puts("Enter values for a (can be negative) and b:");
   scanf("%ld %d", &a, &b);

   c = labs(a*b);  /* Calculate absolute value.                   */

   printf("The absolute value of their product = %ld\n", c );
}


RELATED FUNCTIONS

abs , fabs


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.