#include<stdio.h>
void hanoi(int n,char one,char two,char three);
void move(char a,char b);
void main()
{
int n;
printf("input the number of diskes:\n");
scanf("%d",&n);
printf("the step to moving %d diskes:\n",n);
hanoi(n,'A','B','C');
}
void move(char a,char b)
{
printf("%c-->%c\n",a,b);
}
void hanoi(int n,char one,char two,char three)
{
if(n==1)
move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
学习C/C++语言:递归求解hanoi汉诺塔问题
最新推荐文章于 2024-04-09 21:09:33 发布