Hanoi Tower Problems
It is said that A brass plate was placed in the holy temple of benales in ancient India, and three gem columns (A, B, and C columns may be set) were inserted on the plate, on the gem column, from top to bottom, there are 64 gold disks in ascending order. The 64 gold disks on the column must be moved to the C column according to the following rules.
Rules:
① Only one plate can be moved at a time;
② The plate can only be stored on three columns;
③ The dashboard cannot be placed on a small disk at any time.
Task: enter a positive integer n (number of plates on column A) and output the moving process to column C.
Analysis: set n plates on.
1. n = 1, the disc is directly moved from A to C.
2. n = 2, then:
① Move one disc on A to B;
② Move A disc on A to C;
③ Finally, move one disc on B to C.
★★★With the code, it's easy to do.★★★
Code serving Pipeline
# Include <stdio. h> void hanoi (int n, char A, char B, char C) {if (n = 1) printf ("% c → % c", A, C ); else {hanoi (n-1, A, C, B); printf ("% c → % c \ n", A, C); hanoi (n-1, B,, c) ;}} int main () {hanoi (20, 'x', 'y', 'z ');}
Download C ++ and Dev-C ++