C Library Functions -div()
C Standard Library - <stdlib.h>
Description
C Library Functionsdiv_t div(int numer, int denom)holdnumer (numerator)divided bydenom (denominator)。
Declaration
Below is the declaration of the div() function.
div_t div(int numer, int denom)
Parameter
- numer -- numerator.
- denom -- denominator.
Return Value
This function returns a value of a structure defined in <cstdlib>, which has two members, such as div_t:int quot; int rem;。
Example
The following example demonstrates the usage of the div() function.
#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 us compile and run the above program, which will produce the following result:
(27/ 4) 的商 = 6 (27/4) 的余数 = 3 (27/ 3) 的商 = 9 (27/3) 的余数 = 0other extensions