Hanoi (Hanoi) tower problem (C implementation)

Source: Internet
Author: User

650) this.width=650; "title=" Qq20151018170640.png "src=" http://s3.51cto.com/wyfs02/M00/74/97/ Wkiol1yjyv2a0pyzaabfqbojfww783.jpg "alt=" Wkiol1yjyv2a0pyzaabfqbojfww783.jpg "/>

Hanoi (Hanoi) tower problem. This is a classic mathematical problem: There is a Vatican tower in ancient times, the tower has 3 seats a,b,c, the beginning of a block on the 64 plates, the size of the plate, large in the lower, small on the. There was an old monk who wanted to move the 64 plates from block a to block C, but only one plate was allowed to move at a time, and in the course of the movement, all the 3 seats remained on the market, and the small plate was on. In the movement process can use the C block, give the movement process.

#include <stdio.h> #include <stdlib.h>void move (char Ch1,char CH2) {printf ("%c-->%c\n", CH1,CH2);}  void Hanoi_tower (int num,char C1,char C2,char c3) {if (1 = = num) Move (C1, C3); else {hanoi_tower (num-1, C1, C3, C2);  Move (C1, C3); Hanoi_tower (num-1, C2, C1, C3);  }}int Main () {int N; printf ("Please enter the number of plates to be moved \ n"), scanf_s ("%d", &n); printf ("Steps to move: \ n"); Hanoi_tower (N, ' A ', ' B ', ' C '); System ("pause"); return 0;}

Operation Result:

650) this.width=650; "title=" Qq20151018173435.png "src=" http://s3.51cto.com/wyfs02/M00/74/97/ Wkiol1yjz-gytnaqaacpqx58chw726.jpg "alt=" Wkiol1yjz-gytnaqaacpqx58chw726.jpg "/>

Hanoi (Hanoi) tower problem (C implementation)

Related Article

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.