L1-013. Computing factorial sums

L1-013. Computing the factorial sum
For a given positive integer N, requires you to compute S = 1! + 2! + 3! + … + N!.
Input format:
Input gives a positive integer N up to 10 in one line.
Output format:
Output the value of S in one line.
Input sample:
3
Output sample:
9
Note: Details determine success or failure. When designing code, you must have a clear mind. Eagerness is the biggest mistake of a programmer

#include<stdio.h>
int main()
{
    int i, j, N, sum=1, t;
    scanf("%d", &N);
    for (i=2; i<=N; i++){
        t = 1;//最容易这里犯错,第二次循环一定要将t初始化为1!!!
        for (j=1; j<=i; j++){
             t = t*j;
        }
        sum += t;
    }
    printf("%d", sum);
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325584506&siteId=291194637