c递归程序

递归

long recursin(int);
void main()
{
    int n;
    long result;

    printf("input a integer number: \n");
    scanf("%d", &n);

    result = recursin(n);
    printf("%d! = %ld\n", n, result);
}


long recursin(int n)
{
    long temp_result;
    if(n<0)
    {
        printf("n<0, input error!\n");
    }
    else if(n == 0 || n == 1)
    {
        temp_result = 1;
    }
    else
    {
        temp_result = recursin(n-1) * n;
    }
    return temp_result;
}

 

posted @ 2017-04-22 14:02  我当道士那儿些年  阅读(202)  评论(0编辑  收藏  举报