Learn about labs() function to find absolute value in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
labs() function to find absolute value in C
#include<stdio.h>
#include<stdlib.h>
int main()
{
long int n;
printf("Enter a long integer number: ");
scanf("%ld", &n);
n = abs(n);
printf("Absolute value = %ld\n", n);
return 0;
}
Output:
Enter a long integer number: -4351
Absolute value = 4351
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Program to return Absolute value in C
C program to find the largest of three numbers using if statements