411 REFERENCE · Wikibooks
C++ Programming/Code/Standard C Library/Functions/div
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
div
#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 );
Related topics ldiv