C语言 c++ php mysql nginx linux lnmp lamp lanmp memcache redis 面试 笔记 ppt 设计模式 问题 远程连接

C语言小技巧

 

/*
求阶乘时设置最大调用层数,防止栈占满
当从函数进入另一个函数时当前函数的内容会入栈,另一个函数调用完时在出栈
*/
int factorial(int n, int level)
{
    //printf("%d \n", level);

    if(level>3)
    {
        printf("exit");
        return -1;
    }
    if(n==0 || n==1)
    {
        return 1;
    }

    return n*fn(n-1,++level);
}

 

posted on 2014-10-21 23:56  思齐_  阅读(200)  评论(0编辑  收藏  举报