1 #include <stdio.h> 2 #include <stdlib.h> 3 4 void moveDisks(int n, char x, char y, char z) 5 { 6 if(n == 1) 7 { 8 printf("Move disk %d from %c to %c\r\n", 9 n, x, y); 10 } 11 else 12 { 13 moveDisks(n-1, x, z, y); 14 printf("Move disk %d from %c to %c\r\n", 15 n, x, y); 16 moveDisks(n-1, z, y, x); 17 } 18 } 19 20 int main(void) 21 { 22 int n; 23 printf("Enter number of disks: "); 24 scanf("%d", &n); 25 printf("The moves are: \r\n"); 26 moveDisks(n, ‘A‘, ‘B‘, ‘C‘); 27 return 0; 28 }
原文:http://www.cnblogs.com/utank/p/3603128.html