#include<stdio.h>
void fun(int x){
if(x/2>1)
fun(x/2);
printf("%d ", x);
}
int main(){
fun(7);
printf("\n");
return 0;
}
#include<stdio.h>
void fun(int x){
if(x/2>1)
fun(x/2);
printf("%d ", x);
}
int main(){
fun(7);
printf("\n");
return 0;
}
因为这是递归调用(堆栈原理,后进先出),后调用的先运行结果。
if(x/2>1)
fun(x/2); //该方法的调用结果先打印。
如果打印语句放在函数的最前面打印的是73,
现在打印语句是放在最后面就是37了,类似于二叉树的后根遍历。