[PTA] 7-41 and factorial (10 minutes)

For a given positive integer N, you need to calculate S = 1! +2! +3! + ... + N !.

Input format:
input line in a given positive integer of not more than 10 N.

Output format:
output value S in a row.

Sample input:
3

Sample output:
9

#include <stdio.h>
int main() 
{
    int s=0,n,i=1,x=1;
    scanf("%d",&n);
    while(i<=n){
        s=s+x;
        x=x*(i+1);
        i++;
    }
    printf("%d",s);
return 0;
}

Published 48 original articles · won praise 0 · Views 301

Guess you like

Origin blog.csdn.net/weixin_46399138/article/details/105423605