数学趣题——汉诺塔
1: #include <stdio.h>
2:
3: void move(int n, char x, char y, char z)
4: {
5: if(n == 1)
6: printf("%c-->%c\n", x, z);
7: else
8: {
9: move(n - 1, x, z, y);
10: printf("%c-->%c\n", x, z);
11: move(n - 1, y, x, z);
12: }
13: }
14:
15: int main(void)
16: {
17: int n;
18: printf("input diskes number:\n");
19: scanf("%d", &n); /*输入盘子数目n*/
20: printf("The step to moving %d diskes:\n", n);
21: move(n, 'A', 'B', 'C'); /*递归调用move,求解盘子的搬运过程*/
22:
23: return 0;
24: }
25: