1 2 void move(int n, char a, char b, char c) 3 { 4 if (n == 1) 5 printf("\t%c->%c\n", a, c); 6 else 7 { 8 move(n - 1, a, c, b); 9 printf("\t%c->%c\n", a, c); 10 move(n - 1, b, a, c); 11 } 12 } 13 14 int main() 15 { 16 int n; 17 printf("请输入要移动的块数:"); 18 scanf_s("%d", &n); 19 move(n, ‘a‘, ‘b‘, ‘c‘); 20 return 0; 21 }
原文:http://www.cnblogs.com/MrListening/p/5521949.html