【文件属性】:
文件名称:C语言.汉诺塔.cpp
文件大小:452B
文件格式:CPP
更新时间:2022-04-26 04:49:03
汉诺塔
#include
void hanoi(int n,char one,char two,char three)
{
void move(char x,char y);
if(n==1)
move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void move(char x,char y)
{
printf("\t%c->%c\n",x,y);
}
main()
{
int m;
printf("Input the number of diskes:");
scanf("%d",&m);
printf("The step to move %d diskes:\n",m);
hanoi(m,'A','B','C');
}