给定正整数n,求不大于n的正整数的阶乘的和(即求1!+2!+3!+...+n!)
#include<bits/stdc++.h> using namespace std; int main() { int n,jc=1,sum=0; cin>>n; for(int i=1;i<=n;i++){ jc=1; for(int j=1;j<=i;j++){ jc*=j; } sum+=jc; } cout<<sum; return 0; }
给定正整数n,求不大于n的正整数的阶乘的和(即求1!+2!+3!+...+n!)
#include<bits/stdc++.h> using namespace std; int main() { int n,jc=1,sum=0; cin>>n; for(int i=1;i<=n;i++){ jc=1; for(int j=1;j<=i;j++){ jc*=j; } sum+=jc; } cout<<sum; return 0; }