汉诺一问题计算机是怎样执行的,比如n的值是3,急回,谢谢了。
#include <stdio.h>
void step(int n,char one,char two,char three)
{ void move(char x,char y);
if(n==1)
move(one,three);
else
{
step(n-1,one,three,two);
move(one,three);
step(n-1,two,one,three);
}
}
void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
void main()
{
int n;
printf("这n个盘子的步骤是:\n");
scanf("%d",&n);
step(n,'A','B','C');
}