div [C++ Reference]
Keywords: c,math,div
Date: 2009-03-20T00:03:11-0700

[[div]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## div

Syntax:

        #include <cstdlib>
        div_t div( int numerator, int denominator );

The function div() returns the quotient and remainder of the operation numerator / denominator. The div_t structure is defined in cstdlib, and has at least:

         int quot;   // The quotient
         int rem;    // The remainder

For example, the following code displays the quotient and remainder of x/y:

         div_t temp;
         temp = div( x, y );
         printf( "%d divided by %d yields %d with a remainder of %d\n",
                 x, y, temp.quot, temp.rem );

C++ also provides the following overloaded form:

        #include <cstdlib>
        ldiv_t div( long numerator, long denominator ); // same as ldiv()

Related Topics: ldiv

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •