1 #include<stdio.h>
2 int main()
3 {
4 void hanoi(int n,char one,char two,char three);
5 int m;
6 printf("The step to move %d disks:\n",m);
7 scanf("%d",&m);
8 hanoi(m,'A','B','C');
9 return 0;
10 }
11
12 void hanoi(int n,char one,char two,char three)//定义汉诺函数,作用是把n个盘子,从第一个柱子,经第二个柱子移动到第三个柱子
13 {
14 void move(char x,char y);
15 if(n==1)
16 move(one,three);
17 else
18 {
19 hanoi(n-1,one,three,two);
20 move(one,three);
21 hanoi(n-1,two,one,three);
22 }
23 }
24
25 void move(char x,char y)//定义移动函数,作用是把x柱子上的盘子移动到y柱子上
26 {
27 printf("%c->%c\n",x,y);
28 }