Table of contents
What is abs in c programming?
abs in c is used to find out absolute value of given number.
This function is defined in stdlib.h header file.
Prototype
#include<stdlib.h>
int abs(int m);
Parameter
abs function takes integral value as parameter.
Return value
This function returns absolute value of given integral value.
Example program for abs in c
#include<stdio.h>
#include<stdlib.h>
int main()
{
int x;
x=abs(-100);
printf("The absolute value of given integer is %d \n",x);
return 0;
}
While using gcc use below command to add math header.
gcc file_name.c -lm
Code explanation
abs function is called by passing the input value. The absolute value is printed on to the console.
Difference between abs and fabs in c
abs in c is used to find out the absolute value of a given number. fabs is used to find out the absolute value of the double type of data.
Prototypes are as follows
int abs(int m);
double fabs(double y);
abs( ) | fabs( ) |
Used to find out absolute value of integer type of data. | Used to find out absolute value of double type of data. |
int abs(int m); | double fabs(double y); |
People also ask for
What is absolute value of a number?
Absolute value of number means distance from zero. It is always positive.
What is abs in c?
abs in c is the mathematical function that is used to find out the absolute value of the given integral value.