#include<stdio.h>
void move(int n,int a,int b,int c);
void main()
{
int h;
printf("\input number :\n");
scanf("%d",&h);
printf("the step to moving %2d diskes:\n",h);
move(h,'a','b','c');
}
void move(int n,int a,int b ,int c)
{
if(n==1)
printf("%c-->%c\n",a,c);
else
{
move(n-1,a,c,b);
printf("%c-->%c\n",a,c);
move(n-1,b,a,c);
}
}
我觉得无论塔的个数是奇数还是偶数按这个程序第一步都该输出 a-->b,但为什么塔的个数是偶数时第一步的输出就变成 a-->c了。
谢了,我的意思是您能具体实施以下当塔的个数为3和4时的具体步骤吗?我觉得按这个程序,第一步始终是a--->b
追答h=3:
盘1a-->c
盘2a-->b
盘1c-->b
盘3a-->c
盘1b-->a
盘2b-->c
盘1a-->c
h=4:
盘1a-->b
盘2a-->c
盘1b-->c
盘3a-->b
盘1c-->a
盘2c-->b
盘1a-->b
盘4a-->c
盘1b-->c
盘2b-->a
盘1c-->a
盘3b-->c
盘1a-->b
盘2a-->c
盘1b-->c
呼!写完了
额,虽然不是我想要的结果,但是还是谢谢了,这10分就送给你吧,谢了,你真聪明。