We will learn this tutorial about labs Arithmetic function in C programming language
In the C Programming Language, the labs() is an arithmetic function, which returns the absolute value of a long integer
Syntax
The syntax of the labs() function in the C programming Language
long int labs(long int x);
x of the parameter or argument of this function for find absolute value of given long integer value
when passing a value for x, this function returns the absolute value of x
In the C Language, the required header file for labs() function is
#include <math.h>
Program 1
The following example explains the usage of fabc() function
#include <stdio.h> #include <stdlib.h> int main() { long int a=659644L, b=-129888854L; printf("Absolute value of a : %ld\n",labs(a)); printf("Absolute value of b : %ld\n",labs(b)); getch(); return 0; }
When compile and run above program, this will produce the following result
absolute value of a:659644 absolute value of a:129888654
Program 2
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { long int m,n,o,p;//diclare of local variable printf("Enter the long positive number\n"); //get input positive scanf("%ld",&n); printf("Enter the long Negative number\n"); //get input negative scanf("%ld",&o); m=labs(n);//assign absolute value of n to m p=labs(o);//assign absolute value of o to p printf("absolute value of the positive value is: %ld\n",m); printf("absolute value of the Negative value is: %ld",p); //display labs values of given values getch(); return 0; }
When compile and run above program, this will produce the following result
Enter the long positive number 456783 Enter the long positive number -542334 absolute value of te positive value is:456783 absolute value of the negative value is:542334
Other C programming language functions that are similar to the fabs() function
abs () function in c language
fabs() function in c language
floor() function in C language
round() function in C language
Suggested for you
Function in C language
User defined function in C language
Arithmetic functions in C Language
String function in C language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…