labs Arithmetic function in C programming language
- Home
- pre-define maths function in C
- labs Arithmetic function in C programming language
- On
- By
- 0 Comment
- Categories: pre-define maths function in C
labs Arithmetic function in C programming language
labs Arithmetic function in C programming language
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
Declaration
Syntax
The syntax of the labs() function in the C programming Language
long int labs(long int x);
parameters or Argument
x of the parameter or argument of this function for find absolute value of given long integer value
Return value
when passing a value for x, this function returns the absolute value of x
Required Header
In the C Language, the required header file for labs() function is
#include <math.h>
Example
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