fun(int x) {if (x/2>0) fun(x/2); printf("%d",x); } main() {f
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/26 08:50:13
fun(int x) {if (x/2>0) fun(x/2); printf("%d",x); } main() {fun(6);}
为什么输出的是136
为什么输出的是136
调用顺序:fun(6); fun(3); fun(1);
执行 fun(1),输出:1,
然后返回 fun(3),输出:3,
然后返回 fun(6),输出:6,
最后返回主函数.
再问: 不好意思啊你能把这个过程在描述的更具体些吗,我对递归实在纠结啊
再答: 在 fun(6) 中执行 fun(3),必须等 fun(3) 返回后才会继续执行 fun(6) 的 printf语句,所以 6 是在最后才输出的。 在 fun(3) 中执行 fun(1),必须等 fun(1) 返回后才会继续执行 fun(3) 的 printf语句,所以 3 是在倒数第二个输出的。 在 fun(1) 中由于 1/2==0,所以不再调用 fun 函数。直接输出:1——这是最先输出的。
执行 fun(1),输出:1,
然后返回 fun(3),输出:3,
然后返回 fun(6),输出:6,
最后返回主函数.
再问: 不好意思啊你能把这个过程在描述的更具体些吗,我对递归实在纠结啊
再答: 在 fun(6) 中执行 fun(3),必须等 fun(3) 返回后才会继续执行 fun(6) 的 printf语句,所以 6 是在最后才输出的。 在 fun(3) 中执行 fun(1),必须等 fun(1) 返回后才会继续执行 fun(3) 的 printf语句,所以 3 是在倒数第二个输出的。 在 fun(1) 中由于 1/2==0,所以不再调用 fun 函数。直接输出:1——这是最先输出的。
fun(int x) {if (x/2>0) fun(x/2); printf("%d",x); } main() {f
#include fun(int x) {if(x/2>0)fun(x/2) printf("%d",x%2); } m
#includevoid fun(int x){ if(x/2>0) fun(x/2);printf("%d",x);}
#include void fun(int x) { if(x/2>0)fun(x/2); printf("%d",x)
#include fun(int x) { if(x/2>0)fun(x/2); printf("%d",x); } m
fun(int k) {if(k>0)fun(k-1) printf("%d",k); } main() {int w=
void main() {int x=4;if(x++>=5)printf("%d/n",x);else printf(
int fun(int x) { int y; if(x>1) y=fun(x-1)+2; else y=2; retu
#include void fun(int x) { x=20; } main() { int x=10; fun(x)
#include main() { int x; scanf("%d",x-5); if(x>15)printf("%d
fun(int x) {int p; if(x==0||x==1) return(3); p=x-fun(x-=2);
main( ) {int x=3; do {printf("%d\n",x-=2;} while (--x)); }