汉诺塔
# include"stdio.h"
void move(char,char);
void hanoi(int,char,char,char);
main()
{
int m;
printf("Enter the number of disks to move:");
scanf("%d",&m);
printf("The step to moving%3ddisk:",m);
hanoi(m,'A','B','C');
return 0;
}
void hanoi(int n,char a,char b,char c)
{
if(n==1)
move(a,c);
else
{
hanoi(n-1,a,c,b);
move(a,c);
hanoi(n-1,b,a,c);
}
}
void move(char ch1,char ch2)
{
printf("%c->%c",ch1,ch2);
}