|

楼主 |
发表于 2013-11-17 18:24:51
|
显示全部楼层
#include <stdio.h>
void main()
{
void hanoi (int n, char one, char two, char three);
/*对hanoi函数的声明*/
int m;
printf ("input the number of diskes : ");
scanf ("%d", &m);
printf ("The step to moveing %d diskes:\n", m);
hanoi (m, 'A', 'B', 'C');
}
void hanoi (int n, char A, char B, char C)
/*定义hanoi函数,将n个盘从A座借助B座,移到C座*/
{
void move (char x, char y); /*对move函数的声明*/
if (n == 1)
{
move (A ,C);
}
else
{
hanoi (n - 1, A, C, B);
move (A, C);
hanoi (n - 1, B, A, C);
}
}
void move (char x, char y) /*定义move函数*/
{
printf ("%c --> %c\n", x, y);
}
|
|