Computer >> Máy Tính >  >> Lập trình >> C ++

Hàm lldiv () trong C ++ STL

Hàm lldiv () trong C ++ STL cho kết quả là thương và phần dư của phép chia hai số.

Thuật toán

Begin
   Take two long type numbers as input.
   Call function lldiv().
   Print the quotient and remainder.
End.

Mã mẫu

#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;
}

Đầu ra

Quotient of 500/25 = 20
Remainder of 25/25 = 0