C library functions - div ()
C standard library - <stdlib.h>
description
C library functionsdiv_t div (int numer, int denom ) the numer (numerator)divided bydenom (denominator).
statement
Here is div () function's declaration.
div_t div(int numer, int denom)
parameter
- numer - molecules.
- denom - denominator.
return value
The function returns defined in <cstdlib> value in the structure, the structure has two members, such asdiv_t: int quot; int rem;.
Examples
The following example demonstrates div () function is used.
#include <stdio.h> #include <stdlib.h> int main() { div_t output; output = div(27, 4); printf("(27/ 4) 的商 = %d\n", output.quot); printf("(27/4) 的余数 = %d\n", output.rem); output = div(27, 3); printf("(27/ 3) 的商 = %d\n", output.quot); printf("(27/3) 的余数 = %d\n", output.rem); return(0); }
Let's compile and run the above program, which will result in the following:
(27/ 4) 的商 = 6 (27/4) 的余数 = 3 (27/ 3) 的商 = 9 (27/3) 的余数 = 0