汉若塔问题(c)


/*
汉若塔问题
*/

#define  N 3

main()
{
    hanoi(N,
' A ' , ' B ' , ' C ' );
    getch();
}

hanoi(
int  n, char  A, char  B, char  C)
{
    
if (n == 1 )
    {
        printf(
" move %d from %c to %c\n " ,n,A,C);
    }
    
else
    {
        hanoi(n
- 1 ,A,C,B);
        printf(
" move %d from %c to %c\n " ,n,A,C);
        hanoi(n
- 1 ,B,A,C);
    }
}

你可能感兴趣的:(问题)