abs -- Integer Conversion: Absolute Value

SYNOPSIS

 #include <stdlib.h>
 int abs(int y);
 

DESCRIPTION

abs returns the absolute value of an integer.

RETURN VALUE

abs returns the absolute value of its argument.

IMPLEMENTATION

abs is implemented by a built-in function unless it is undefined by an #undef statement.

EXAMPLE

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

  #define BASELINE 32

  main()
  {
     int  range, temp;
     puts("The average temperature in NY in December is 32 degrees.");
     puts("Enter the average temperature in NC in December:");
     scanf("%d", &temp);

     range = abs(BASELINE - temp);    /* Calculate range. */

     printf("The average temperatures differ by: %dn", range );
  }

 

RELATED FUNCTIONS

fabs, labs

SEE ALSO

Mathematical Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.