Mathematical Functions for Integer Types
The mathematical
functions for the types
int and long are declared in
stdlib.h.
-
intrand( void ); Generates a random number between
0andRAND_MAX. The constantRAND_MAXhas a value of at least 32767, or 215 - 1.-
voidsrand( unsignedn); Initializes the random number generator with the seed
n. After this function has been called, calls torand()generate a new sequence of random numbers.-
intabs( intx); Returns the absolute value of
x.-
div_tdiv( intx, inty); Divides
xbyyand stores the integer part of the quotient and the remainder in a structure of typediv_t, whose membersquot(the quotient) andrem(the remainder) have typeint. The typediv_tis defined in stdlib.h.
The corresponding (to abs() and
div()) functions
labs()
,
llabs()
(*),
lldiv()
(*), and
ldiv()
are also provided for integers of type
long
long(*). Furthermore, the
functions imaxabs()
(*) and
imaxdiv()
(*) are
defined for the type
intmax_t
(*). These
functions are declared in
inttypes.h
(*).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access