C / C ++库函数div_t div(int numer,int denom)将numer(分子)除以denom(分母)。下面是div()函数的声明。
div_t div(int numer, int denom)
参数是分子和分母。此函数以<cstdlib>定义的结构返回该值,该结构具有两个成员。对于div_t:int quot; 诠释
#include <iostream> #include <cstdlib> using namespace std; int main () { div_t output; output = div(27, 4); cout << "Quotient part of (27/ 4) = " << output.quot << endl; cout << "Remainder part of (27/4) = " << output.rem << endl; output = div(27, 3); cout << "Quotient part of (27/ 3) = " << output.quot << endl; cout << "Remainder part of (27/3) = " << output.rem << endl; 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