Library function in C

abs Arithmetic function in C programming language

abs Arithmetic function in C programming language

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.

abs Arithmetic function

Declaration

Syntax

The syntax of  the abs() function in the C programming Language

int abs(int x);

parameters or Argument

x is the parameter or argument of this function.

Return value

When a value for x is passed, this function returns the absolute value of x

Required Header

In the C Language, the required header file for abs() function is

#include <stdlib.h>

Example

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      

cosh function   in C  language                               

sinh function in C language

tanh function in C language

abs function in C language

floor function in C language

ceil function in C language

round function in C language

sqrt function in C language

pow function in C language

exp function in C language

log function in C language

log10 function in C language

trunc function in C language

 

Function in C language

User defined function in C language

Arithmetic functions in C Language

String function in C language

fabs function

labs function

 

 

 

Arithmetic function in C programming language
fabs Arithmetic function in C programming Language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago