#include
#include
int fun(int x)
{
int p;
if (x == 0 || x == 1)
p = 3;
else
p = x - fun(x - 2);
return p;
}
main()
{
printf("%d\n", fun(7));
system("pause");
return 0;
}
#include
#include
int fun(int x)
{
int p;
if (x == 0 || x == 1)
p = 3;
else
p = x - fun(x - 2);
return p;
}
main()
{
printf("%d\n", fun(7));
system("pause");
return 0;
}
入栈过程:
fun(7) = 7 - fun(5);
fun(5) = 5 - fun(3);
fun(3) = 3 - fun(1);
fun(1) = 3;
出栈过程:
fun(3) = 3 - 3 = 0;
fun(5) = 5 - 0 = 5;
fun(7) = 7 - 5 = 2;
这种过程一下子看不懂就慢慢写出来好好理解下。