div() function in C++
C / C++ 库函数 div_t div(int numer, int denom) 将 numer(分子)除以 denom(分母)。以下是 div() 函数的声明。
div_t div(int numer, int denom)
参数是分子分母。此函数在 <cstdlib> 中定义的结构中返回一个值,该结构有两个成员。对于 div_t:int quot; int rem;
示例
#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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP