imaxdiv


imaxdiv

Performs integer division, returning quotient and remainder

 #include <inttypes.h> imaxdiv_t imaxdiv ( intmax_t dividend , intmax_t divisor  ); 

The imaxdiv( ) function is the same as either ldiv( ) or lldiv( ), depending on how many bits wide the system's largest integer type is. Accordingly, the structure type of the return value, imaxdiv_t, is the same as either ldiv_t or lldiv_t.

Example

 intmax_t people = 110284, apples = 9043291; imaxdiv_t  share; if ( people == 0 )              // Avoid dividing by zero.     printf( "There's no one here to take the apples.\n" ), return -1; else   share = imaxdiv( apples, people ); printf( "If there are %ji of us and %ji apples,\n"         "each of us gets %ji, with %ji left over.\n",         people, apples, share.quot, share.rem ); 

This example prints the following output:

 If there are 110284 of us and 9091817 apples, each of us gets 82, with 3 left over. 

See Also

The description under div( ) in this chapter; the floating point functions remainder( ) and remquo( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net