C labs() library function

The function labs 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 using 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;

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