阶乘1到阶乘n的和

#include
int main()
{
    int n,s=0;
    int i,j;
    scanf("%d",&n);
    for( i=1;i<=n;i++)
    {
        int factorial=1;
        for( j=1;j<=i;j++)
        {
            factorial*=j;
        }
        s+=factorial;
    }
    printf("%d\n",s);
    return 0;
}
#include
void main()
{
    int i;
    int n;
    int sum=0,fact=1,j=1;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        while(j<=i)
        {
            fact=j*fact;
            j++;

        }
        sum=sum+fact;
    }
    cout<<sum;
}

 

转载于:https://www.cnblogs.com/2228212230qq/p/7787479.html

你可能感兴趣的:(阶乘1到阶乘n的和)