Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

div - Division with integers (int)

&pagelevel(4)&pagelevel

Definition  

#include <stdlib.h>

div_t div(int dividend, int divisor);

div calculates the quotient and the remainder of the division of dividend by divisor.
The sign of the quotient is the same as the sign of the algebraic quotient. The value of the quotient is the highest integer less than or equal to the absolute value of the algebraic quotient.

The remainder is expressed by the equation: Quotient * Divisor + Remainder = Dividend

Return val.

Structure of type div_t


           

containing both the quotient quot and the remainder rem as integer values.

Example

div_t d;
d = div( 7, 3);        /*  d.quot =  2,  d.rem =  1  */
d = div(-7, 3);        /*  d.quot = -2,  d.rem = -1  */
d = div( 7,-3);        /*  d.quot = -2,  d.rem =  1  */
d = div(-7,-3);        /*  d.quot =  2,  d.rem = -1  */

See also

ldiv, lldiv