#include
int time = 0;
void Hanoi(int n,char a,char b,char c){
if(n==1)
{
printf("%d:將頂環從%c移至%c\n",++time,a,c);
}
else
{
Hanoi(n-1,a,c,b);
Hanoi(1,a,b,c);
Hanoi(n-1,b,a,c);
}
}
int main(void) {
int n;
char a='A',b='B',c='C';
scanf("%d",&n);
printf("輸入環數為:%d\n",n);
Hanoi(n,a,b,c);
return 0;
}
0 意見:
張貼留言