Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - labs()

C library function - labs()

C Standard Library - <stdlib.h> C Standard Library -

Description

C Library Function long int labs(long int x) Return x the absolute value of

Declaration

Here is the declaration of the labs() function.



long int labs(long int x)

Parameters

Return Value

This function returns the absolute value of x.

Example

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



#include 

#include 



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's compile and run the above program, which will produce the following result:



a 的值 = 65987

b 的值 = 1005090

C Standard Library - <stdlib.h> C Standard Library -