/* 汉诺塔 */
#include <stdio.h>
#include <stdlib.h>
void move(int,int,int,int);
int main()
{
int n , a = 'A', b = 'B',c = 'C';
printf("Tower of HANOI\n");
printf("The problem starts with n disks on Tower A\nInput n :" );
if((scanf("%d",&n)!=1||n<1))
{
printf("\nError :Positer interger not found \n");
return -1;
}
move(n,a,b,c);
return 0;
}
void move(int n,int a,int b,int c)
{
static int i = 1;
if(n==1)
{
printf("step %d: %c-->%c\n",i++,a,c); //把a上盘子移到c
}
else
{
move(n-1,a,c,b); //递归调用:把a上的n-1的盘子借助c移到b
printf("step %d: %c-->%c\n",i++,a,c);
move(n-1,b,a,c); //递归调用:把b上的n-1的盘子借助a移到c
}
}