//加一个静态变量
#include <stdio.h>
void hanio (int n, char A, char B, char C);
void move (char x,char y);
int main()
{
int n;
printf("input the number of diskes: ");
scanf("%d",&n);
printf("the step to moving %d diskes:\n", n);
hanio (n,'A','B','C');
getchar();
getchar();
return 0;
}
void hanio (int n, char A, char B, char C)
{
if (n==1)
move (A,C);
else
{
hanio(n-1,A,C,B);
move (A,C);
hanio(n-1,B,A,C);
}
}
void move (char x, char y)
{
static int i = 0;
i++;
printf("%d: %c -----> %c\n",i,x,y);
}
[[it] 本帖最后由 andyzhshg 于 2008-5-30 20:49 编辑 [/it]]