We will learn about abs Arithmetic function in C programming language
In the C Programming Language, the abs() Arithmetic function returns the absolute value of an integer. The absolute value of a number is always positive.
Syntax
The syntax of the abs() function in the C programming Language
int abs(int x);
x is the parameter or argument of this function.
When a value for x is passed, this function returns the absolute value of x
In the C Language, the required header file for abs() function is
#include <stdlib.h>
Program 1
The following example explains the usage of abs() function
#include <stdio.h> #include <stdlib.h> int main() { int a=10,b=-12; printf("the absolute value of a: %d\n",abs(a)); printf("the absolute value of b: %d\n",abs(b)); getch(); return 0; }
When the above program is compiled and run, it will produce the following result
the absolute value of a: 10
the absolute value of b:12
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int m,n,o,p;//diclare of local variable printf("Enter the positive number\n"); //get input positive scanf("%d",&n); printf("Enter the Negative number\n"); //get input negative scanf("%d",&o); m=abs(n);//assign absolute value of n to m p=abs(o);//assign absolute value of o to p printf("absolute value of the positive value is: %d\n",m); printf("absolute value of the Negative value is: %d",p); getch(); return 0; }
When the above program is compiled and run, it will produce the following result
Enter the positive number
56
Enter the Negative number
-76
the absolute value of the positive value is: 56
the absolute value of the Negative value is: 78
Similar Functions
Other C programming language functions that are similar to the cosine function
User defined function in C language
Arithmetic functions in C Language
How to find reverse number using method In this article, we will discuss the concept…
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…