lldiv()是C++ STL中的內置函數,可為我們提供兩個數字除法的商和餘數。
用法:
lldiv(n, d)
參數:該函數接受兩個強製性參數,如下所述:
- n: 它指定股息。數據類型可以是long long或long long int。
- d: 它指定除數。數據類型可以是long long或long long int。
返回值:該函數返回lldiv_t類型的結構,該結構由兩個成員組成:quot和rem,其中quot是商,rem是餘數。該結構定義如下:
struct lldiv_t { long long quot; long long rem; };
以下示例程序旨在說明上述函數:
程序1:
// C++ program to illustrate the
// lldiv() function
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
long long n = 1000LL;
long long d = 50LL;
lldiv_t result = lldiv(n, d);
cout << "Quotient of " << n << "/" << d
<< " = " << result.quot << endl;
cout << "Remainder of " << n << "/" << d
<< " = " << result.rem << endl;
return 0;
}
輸出:
Quotient of 1000/50 = 20 Remainder of 1000/50 = 0
程序2:
// C++ program to illustrate
// the lldiv() function
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
long long int n = 251987LL;
long long int d = 68LL;
lldiv_t result = lldiv(n, d);
cout << "Quotient of " << n << "/" << d
<< " = " << result.quot << endl;
cout << "Remainder of " << n << "/" << d
<< " = " << result.rem << endl;
return 0;
}
輸出:
Quotient of 251987/68 = 3705 Remainder of 251987/68 = 47
相關用法
- C++ log()用法及代碼示例
- C++ div()用法及代碼示例
- C++ fma()用法及代碼示例
- C++ real()用法及代碼示例
- C++ imag()用法及代碼示例
- C++ map key_comp()用法及代碼示例
- C++ valarray pow()用法及代碼示例
- C++ valarray log()用法及代碼示例
- C++ regex_iterator()用法及代碼示例
- C++ valarray tan()用法及代碼示例
注:本文由純淨天空篩選整理自IshwarGupta大神的英文原創作品 lldiv() function in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。