#include<stdio.h>
void move(char getone,char putone)
{printf("%c-->%c\n",getone,putone);
}void m(int n,char one,char two,char three)
{if(n==1)
move(one,three);
else{m(n-1,one,three,two);
{
move(one,three);
m(n-1,two,one,three);}
}
}
int main(){
int n;
printf("disks:");
scanf("%d",&n);
printf("%3d\n",n);
m(n,'A','B','C');
return 0;
}
调用函数求解汉诺塔问题
最新推荐文章于 2023-04-02 13:53:55 发布