关于递归基础
#include<stdio.h>#include<windows.h>
void up_and_dowm(int);
intmain(void)
{
up_and_dowm(1);
system("pause");
return 0;
}
void up_and_dowm(int n)
{
printf("Level %d: n location %p\n",n,&n);
if(n<4)
up_and_dowm(n+1);
printf("Level %d: n location %p\n",n,&n);
}
为什么后面有四行降序输出 没有搞明白 n=4的时候printf两次结束后回到n=3 结束if语句 调用if后的printf 以此类推 还不清楚的话就用纸写一下吧{:5_91:} #include<stdio.h>
#include<windows.h>
void up_and_dowm(int);
intmain(void)
{
up_and_dowm(1);
system("pause");
return 0;
}
void up_and_dowm(int n)
{
printf("Level %d: n location %p\n", n, &n);
if (n<4)
up_and_dowm(n + 1);
/*printf("Level %d: n location %p\n", n, &n);
这个printf()是包含在up_and_down里面的。
*/
}
页:
[1]