C++ STL 中的 lldiv() 函式


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

更新於:2019-07-30

92 Views

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告