labs : <stdlib.h> library function

The function long int labs(long int x); returns the absolute value of an long integer x.

Function prototype of labs

long int labs(long int x);
  • x : This is a long integer to convert to an absolute value.

Return value of labs

This function returns absolute value of a long integer represented by x.

C program to show the use of labs function

The following program shows the use of labs function to find absolute value of a long integer.

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

int main(){
    long int value;
    printf("Enter a number\n");
    scanf("%ld", &value);
    printf("Absolute value of %ld = %ld\n", value, labs(value));
    
    return 0;
}

Program Output
Enter a number
5362565
Absolute value of 5362565 = 5362565
Enter a number
-97652745
Absolute value of -97652745 = 97652745
Enter a number
0
Absolute value of 0 = 0