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)