c 语言练习__求到N的阶乘的和。

#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 \n", s);

    }
    else 
        printf("Input Error.\n");

    return 0;
}

 

posted @ 2013-07-25 17:54  playerc  阅读(453)  评论(3编辑  收藏  举报
c4io.com Count Visitors
Web Counter