C ++ STL中的lldiv()函数给出两个数字的商和余数的结果。
Begin Take two long type numbers as input. Call function lldiv(). Print the quotient and remainder. End.
#include <cstdlib> #include <iostream> using namespace std; int main() { long long q = 500LL; long long r = 25LL; lldiv_t res = lldiv(q, r); cout << "Quotient of " << q << "/" << r << " = " << res.quot << endl; cout << "Remainder of " << r << "/" << r << " = " << res.rem << endl; return 0; }
输出结果
Quotient of 500/25 = 20 Remainder of 25/25 = 0