递归函数

 fun是递归函数,调用结果如下:

#include <stdio.h>
void fun(int x)
{                            
    if(x/2>0)                  
    {
           fun(x/2-2);
    }
    printf(" %d ",x);
}
int main()
{
    fun(20);
    printf("
");
}

/*实际递归过程如下
{
    if(20/2>0)    x=20              
    {
           if(8/2>0)        x=8          
        {
               if(2/2>0)           x=2       
            {
                   if(-1/2>0)         x= -1         
                {
           
                }
                printf(" %d ",x);
            }
            printf(" %d ",x);
        }
        printf(" %d ",x);
    }
    printf(" %d ",x);
}*/
原文地址:https://www.cnblogs.com/nanqiang/p/9970549.html