C Library Functions -labs()

C Standard Library - <stdlib.h>

Description

C Library Functionslong int labs(long int x)returnxabsolute value.

Declaration

Below is the declaration of the labs() function.

long int labs(long int x)

Parameter

  • x -- complete value.

Return Value

This function returns the absolute value of x.

Example

The following example demonstrates the usage of the labs() function.

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

int main ()
{
   long int a,b;

   a = labs(65987L);
   printf("a 的值 = %ld\n", a);

   b = labs(-1005090L);
   printf("b 的值 = %ld\n", b);
   
   return(0);
}

Let us compile and run the above program, which will produce the following result:

a 的值 = 65987
b 的值 = 1005090

C Standard Library - <stdlib.h>

other extensions