#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void recursie(int);
int main(int argc, char **argv) {
recursie(3);
}
void recursie(int a){
if(a==0){return;}
recursie(a-1);
printf("%d",a);
recursie(a-1);
}
Run Code Online (Sandbox Code Playgroud)
输出是:1213121.有人可以解释我如何得到这个输出?
recursie(3)
-calls recursie(2)
- calls recursie(1)
-calls recursie(0) -> void
-prints 1
-calls recursie(0) -> void
-prints 2
-calls recursie 1
-calls recursie 0 -> void
-prints 1
-calls recursie 0 -> void
-prints 3
-calls recursie(2)
- calls recursie(1)
-calls recursie(0) -> void
-prints 1
-calls recursie(0) -> void
-prints 2
-callse recurse 1
-calls recusie 0 -> void
-prints 1
-calls recursie 0 -> void
end
Run Code Online (Sandbox Code Playgroud)