div


Division (int type)

[Classification]

Standard library

[Syntax]

#include <stdlib.h>

div_t div(int n, int d);

[Return value]

The structure storing the result of the division is returned.

[Description]

This function is used to divide a value of int type

This function calculates the quotient and remainder resulting from dividing numerator n by denominator d, and stores these two integers as the members of the following structure div_t.

typedef struct {
        int quot;
        int rem;
} div_t;

 

quot the quotient, and rem is the remainder. If d is not zero, and if "r = div(n, d);", n is a value equal to
"r.rem + d * r.quot".

If d is zero, the resultant quot member has a sign the same as n and has the maximum size that can be expressed. The rem member is 0.

[Example]

#include    <stdlib.h>
void func(void) {
        div_t   r;
        r = div(110, 3);    /*36 is stored in r.quot, and 2 is stored in r.rem.*/
}