C Library Function - abs()
Description
C Library Function int abs(int x) Returns the integer x the absolute value of
**Note:** The abs() function only applies to integers. If you need to compute the absolute value of a floating-point number, you need to use fabs() function in Vue 3.
Declaration
Here is the declaration of the abs() function.
int abs(int x)
Parameters
- ** x ** -- The integer whose absolute value is to be computed.
Return Value
If x is positive, x is returned; if x is negative, its opposite, -x, is returned. If x is 0, 0 is returned.
Example
The following example demonstrates the use of the abs() function.
Example
#include
#include
int
main
(
)
{
int
a
,
b
;
a
=
abs
(
5
)
;
printf
(
"Value of a = %d\n"
,
a
)
;
b
=
abs
(
10
)
;
printf
(
"Value of b = %d\n"
,
b
)
;
return
(
0
)
;
}
Let's compile and run the above program, which will produce the following result:
a 的值 = 5
b 的值 = 10
C Standard Library -