C <stdlib.h> - div_t structure type
The C <stdlib.h> div_t is a structure to represent both the quotient and the remainder of the division of the integral numerator by integral denominator. This is the type returned by div() function.
In the <stdlib.h> header file, it is defined as follows:
struct div_t { int quot; int rem; }; or struct div_t { int rem; int quot; };
Example:
The example below shows the usage of <stdlib.h> div_t type.
#include <stdio.h> #include <stdlib.h> int main (){ div_t result = div(50, 17); printf("div(50, 17) gives quotient = %d and remainder = %d\n", result.quot, result.rem); return 0; }
The output of the above code will be:
div(50, 17) gives quotient = 2 and remainder = 16
❮ C <stdlib.h> Library