C abs() function
C abs() function - Calculate integer absolute value
The abs() function is used to compute the absolute value of an integer value.
Syntax abs() function
int abs(int x)
Parameters abs() function
Name | Description | Required /Optional |
---|---|---|
x | Numeric value. | Required |
Return value from abs()
- Absolute value of its integer operand.
Example: abs() function
The following example shows the usage of abs() function.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int x, y;
x = -347;
y = abs(x);
printf("The absolute value of %d is %d\n", x, y);
x = 456;
y = abs(x);
printf("\nThe absolute value of %d is %d\n", x, y);
}
Output:
The absolute value of -347 is 347 The absolute value of 456 is 456
C Programming Code Editor:
Previous C Programming: C qsort()
Next C Programming: C div()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming/stdlib/c-abs.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics