C ++中的div()函数
C/C++库函数div_tdiv(intnumer,intdenom)将numer(分子)除以denom(分母)。下面是div()函数的声明。
div_t div(int numer, int denom)
参数是分子和分母。此函数以<cstdlib>定义的结构返回该值,该结构具有两个成员。对于div_t:intquot;诠释
示例
#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
热门推荐
2 敏字的祝福语简短
10 祝福语老人简短话语
11 新婚祝福语简短十六字
12 牙医生日祝福语简短
13 给儿子生日祝福语 简短
14 新年的祝福语简短的
15 简短祝福语蛋糕简笔画
16 团体年会祝福语简短霸气
17 开业经典祝福语简短
18 祝福语女友文案简短霸气