return quotient and remainder from division

You're viewing an older version of this page (#4050). View the current version.

View versions (3)

INTERFACE

#include <stdlib.h> div_t div ( int num, int denom )

DESCRIPTION

The div function computes the value &#92;c num/denom and returns the quotient and remainder in a structure named &#92;c div_t that contains two int members named quot and rem.

Example 1
Workings

\code #include <stdio.h> #include <stdlib.h> int main() { int a = 100, b = 13; div_t result = div(a, b); printf("100 = 13*%d + %d
", result.quot, result.rem); return 0; } \endcode

Solution

Output:

100 = 13*7 + 9

SEE ALSO

ldiv