C library function - div()
Description
C Library Function div_t div(int numer, int denom) Divides the **numer (numerator)** by denom (denominator).
Declaration
The following is the declaration of the div() function.
div_t div(int numer, int denom)
Parameters
- ** numer ** -- numerator.
- ** denom ** -- denominator.
Return Value
This function returns the value in a structure defined in
Example
The following example demonstrates the use of the div() function.
#include
#include
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 produce the following result:
(27/ 4) 的商 = 6
(27/4) 的余数 = 3
(27/ 3) 的商 = 9
(27/3) 的余数 = 0
C Standard Library -