You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for 循环中 i 最大值为 100,而数组 factorials 大小就是 100 ,从 0 开始算,最大是 99,找不到factorials[100];
ar_size改为101就好了,原书的程序清单5.4也是,size是16,最后输出15的阶乘。
#include
using namespace std;
const int ArSize = 16;
int main() {
long long factorials[ArSize];
factorials[1] = factorials[0] = 1LL;
for (int i = 2; i < ArSize; i++)
{
factorials[i] = i * factorials[i - 1];
}
for (int i = 0; i < ArSize; i++)
{
cout << i << "! = " << factorials[i] << "\n";
}
return 0;
}
The text was updated successfully, but these errors were encountered:
for 循环中 i 最大值为 100,而数组 factorials 大小就是 100 ,从 0 开始算,最大是 99,找不到factorials[100];
ar_size改为101就好了,原书的程序清单5.4也是,size是16,最后输出15的阶乘。
#include
using namespace std;
const int ArSize = 16;
int main() {
long long factorials[ArSize];
factorials[1] = factorials[0] = 1LL;
for (int i = 2; i < ArSize; i++)
{
factorials[i] = i * factorials[i - 1];
}
for (int i = 0; i < ArSize; i++)
{
cout << i << "! = " << factorials[i] << "\n";
}
return 0;
}
The text was updated successfully, but these errors were encountered: