#include<stdio.h>void move(char x,int n,char y){printf("%d号盘 %c柱 ---> %c柱\n",n,x,y);
}void hanoi(int n,char x,char y,char z){if(n==1){move(x,1,z);}else{hanoi(n-1,x,z,y);move(x,n,z);hanoi(n-1,y,x,z);}
}int main(){int n;char x='X';char y='Y';char z='Z';printf("输入盘子的个数:");scanf("%d",&n);hanoi(n,x,y,z);return 0;
}
欢迎留言交流。。。