/*
This program is to simulate the operation process of the tower,
Print the execution method of each step,
And record the number of executions;
The main program uses recursion;
Wait for 0.5 seconds for each execution step;
*/
# Include <stdio. h>
# Include <conio. h>/* for the function: clrscr ()*/
# Include <dos. h>/* for the function: delay (int ms )*/
Int COUNT = 0;/* Move times */
/* Move the disk from column A to Column B */
Void move (char a, char B)
{
Delay (500);/* Wait 0.5 s */
Printf ("/n % d: % C-> % C", ++ count, a, B );
}
/* Tower Master process */
Void Hanoi (int n, char a, char B, char C)
{
If (n <1)
Return;
If (n = 1)
{
Move (a, c );
Return;
}
Hanoi (n-1, A, C, B );
Move (a, c );
Hanoi (n-1, B, A, C );
}
Int main ()
{
Int n = 0;/* Number of plates */
Clrscr ();/* clear the screen */
Printf ("Please input a INT :");
Scanf ("% d", & N );
/* Main process */
Hanoi (n, 'A', 'B', 'C ');
/* Exit with any key */
Printf ("/npress any key to exit! ");
Return getch ();/* wait to get a char */
}