1汉诺塔问题递归实现;
。。
。。上代码!
#include<stdio.h>
void main(){
void hannoi(int n,char one,char two,char three);
int m;
printf("input the number of diskes:");
scanf("%d",&m);
printf("The step to moveing %d diskes:\n",m);
hannoi(m,'A','b','c');
}
//定义函数将n个盘从one座借助two座移动到three座
void hannoi(int n,char one,char two,char three)
{
void move(char x,char y);//对move函数声明
if(n==1)
{
move(one,three);
}else
{
hannoi(n-1,one,three,two);
move(one,three);
hannoi(n-1,two,one,three);
}
}
void move(char x,char y)//定义move移动函数
{
printf("%c-->%c\n",x,y);
}