递归函数解析
源代码
#include <stdio.h>
void fun(int i)
{
if (i > 0)
{
fun(i / 2);
}
printf("%d\n", i);
}
int main(void)
{
fun(10);
return 0;
}
运行结果
[root@localhost lwp_workspace]# ./test
0
1
2
5
10
[root@localhost lwp_workspace]#
递归展开式
/*********************************************
* void fun(int i)
* {
* if (i > 0)
* {
* fun(i/2)
* {
* if (i/4 > 0)
* {
* if (i/8 > 0)
* {
* if (i/16 > 0)
* {
* ...
* }
* printf("%d\n", i/16);
* }
* printf("%d\n", i/8);
* }
* printf("%d\n", i/4);
* }
* printf("%d\n", i/2);
* }
* printf("%d\n", i);
* }
*
*********************************************/