Function abs () in C
Function abs () in C
The function int abs (int x) returns the absolute value of integer x .
Declare the function abs () in C
Here is the declaration section for abs () in C:
int abs ( int x )
Parameters
x : this is an integer value.
Returns the value
Returns the absolute value of x.
For example
The following C program illustrates the usage of abs () in C:
#include #include int main () { int a , b ; a = abs ( 6 ); printf ( "Gia tri cua a = %dn" , a ); b = abs (- 11 ); printf ( "Gia tri cua b = %dn" , b ); return ( 0 ); }
Compiling and running the above C program will produce the following results:
According to Tutorialspoint
Previous lesson: qsort () function in C
Next lesson: Div () function in C
4.5 ★ | 2 Vote
You should read it
May be interested
- Div () function in Cdiv_t div function (int numer, int denom) divides numer numerator for denom.
- Labs () function in Cfunction long int labs (long int x) returns the absolute value of x.
- The function ldiv () in Cthe div_t div function (long int numer, long int denom) divides the numerator numer to denom.
- The function rand () in Cthe function int rand (void) returns a random number in the range from 0 to rand_max.
- The function srand () in Cthe function void srand (unsigned int seed) provides seed for the random number generator used by the rand function.
- The function mblen () in Cthe function int mblen (const char * str, n) returns the length of a multi-byte char pointed to by parameter str.