Hanoi Tower Problems

Source: Internet
Author: User

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 ++

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.