天天看點

遞歸函數解析遞歸函數解析

遞歸函數解析

源代碼

#include <stdio.h>

void fun(int i)
{
    if (i > )
    {
        fun(i / );
    }

    printf("%d\n", i);
}

int main(void)
{
    fun();

    return ;
}
           

運作結果

[root@localhost lwp_workspace]# ./test 





[root@localhost lwp_workspace]# 
           

遞歸展開式

/*********************************************
 * void fun(int i)
 * {
 *     if (i > )
 *     {
 *         fun(i/)
 *         {
 *             if (i/ > )
 *             {
 *                 if (i/ > )
 *                 {
 *                     if (i/ > )
 *                     {
 *                         ...
 *                     }
 *                     printf("%d\n", i/);
 *                 }
 *                 printf("%d\n", i/);
 *             }
 *             printf("%d\n", i/);
 *         }
 *         printf("%d\n", i/);
 *     }
 *     printf("%d\n", i);
 * }
 *
 *********************************************/
           

繼續閱讀