📅  最后修改于: 2023-12-03 14:59:45.086000             🧑  作者: Mango
在C++中,lldiv()函数用于计算两个long long类型的整数的商和余数,返回一个包含商和余数的lldiv_t结构体。注意,lldiv()函数仅支持long long类型的整数。
lldiv_t lldiv (long long numer, long long denom);
参数说明:
返回值:包含商和余数值的lldiv_t结构体。
#include <iostream>
#include <cstdlib>
int main() {
long long numer = 20, denom = 3;
lldiv_t ld = std::lldiv(numer, denom);
std::cout << "The quotient of " << numer << " divided by " << denom << " is " << ld.quot <<
" with a remainder of " << ld.rem << std::endl;
return 0;
}
运行结果:
The quotient of 20 divided by 3 is 6 with a remainder of 2