计算1!+2!+3!+…+n!
1.
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int tmp = 1, ans = 0;
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= i; j ++)
{
tmp *= j;
}
ans += tmp;
tmp = 1;
}
cout << ans << endl;
return 0;
}
2.
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
long long tmp = 1, ans = 0;
for (int i = 1; i <= n; i ++)
{
tmp *= i;
ans += tmp;
}
cout << ans << endl;
return 0;
}
本文来自博客园,作者:逆袭怪,转载请注明原文链接:https://www.cnblogs.com/fghjktgbijn/p/17426189.html