解题思路:
注意事项:
参考代码:
#include<stdio.h>
int main()
{
void hanoi(int n,char x,char y,char z);
int m;
//printf("input the number of dishes:");
scanf("%d",&m);
//printf("The step to moving %d dishes:\n",m);
hanoi(m,'1','2','3');
return 0;
}
void hanoi(int n,char x,char y,char z)
{
void move(int n,char a,char b);
if(n==1)
move(n,x,z);
else
{
hanoi(n-1,x,z,y);
move(n,x,z);
hanoi(n-1,y,x,z);
}
}
void move(int n,char a,char b)
{
printf("Move %d from %c to %c\n",n,a,b);
}
0.0分
1 人评分