返回值
此函数以<cstdlib>这个函数返回中定义的结构中的值,该结构有两个成员。div_t:int quot; int rem;
示例
以下示例显示div函数的用法-
#include <stdio.h>
#include <stdlib.h>
int main () {
div_t output;
output = div(27, 4);
printf("Quotient part of (27/ 4) = %d\n", output.quot);
printf("Remainder part of (27/4) = %d\n", output.rem);
output = div(27, 3);
printf("Quotient part of (27/ 3) = %d\n", output.quot);
printf("Remainder part of (27/3) = %d\n", output.rem);
return(0);
}
尝试一下
让我们编译并运行上面的程序,它将产生以下结果-
Quotient part of (27/ 4) = 6
Remainder part of (27/4) = 3
Quotient part of (27/ 3) = 9
Remainder part of (27/3) = 0