![]() |
![]() |
![]() |
C++ Reference: div()
div()
Declaration
div_t div(int iNumerator, int iDenominator);
Description
This function takes two ints or longs and performs integer division to get a quotient and remainder. The quotient and remainder are returned in the struct type div_t or ldiv_t, depending an whether the call is made with ints or longs. The calculation fits relationship N = Q*D + R, where N, D, Q and R are the numerator, denominator, quotient and remainder, respectively.
Overloads
ldiv_t div(long, long);
Related Functions *
ldiv_t ldiv(long, long);
* Note: Since C does not allow function overloading, these other versions of this function exist.
Example
#include <iostream>
#include <cstdlib>
int main() {
using namespace std;
// Divison example using ints
int iNumerator1 = 17;
int iDenominator1 = 3;
div_t qDivision1 = div(iNumerator1, iDenominator1);
cout << iNumerator1 << " = " << qDivision1.quot << "*"
<< iDenominator1 << " + " << qDivision1.rem << endl;
return 0;
}
Output:
![]() |
![]() |
![]() |
| Home | | | Reference | | | Play Games! | | | Blog | | | Forum | | | Site Map | | | Contact Us |





