c言語練習_Nの階乗の和を求める.

2232 ワード

#include <stdio.h>



/*     

 * S = 1 + 2! + 3! + ... + N!

 */

int main(int argc, char *argv[])

{

    int s = 0;

    int n = 0;

    int i = 1;

    int m = 1;



    printf("Please input N :");

    if (scanf("%d",&n) == 1 ){

        while (i <= n ){        

            m *= i++;

            s += m;        

        }

        printf("The result is %d 
", s); } else printf("Input Error.
"); return 0; }