Tower of Hanoi

. 1 #include <stdio.h>
 2  void Hanoi ( int n-, char x, char Y, char z)
 . 3  /// / n-number of the disk is a disk in the x-z disk into ascending order can not be arranged in a small large top 
. 4  {
 . 5      IF (n-== . 1 )
 . 6      {
 . 7          the printf ( " the disk% c% d from moving% c \ n- " , n-, X, Z);
 . 8      }
 . 9      the else 
10      {
 . 11          Hanoi (n-- . 1 , X, Z, Y);
 12 is          the printf ( "Moving the disk% d% c \ n from C% " , n-, X, Z);
 13 is          Hanoi (n-- . 1 , Y, X, Z);
 14      }
 15  }
 16  int main ()
 . 17  {
 18 is      Hanoi ( . 3 , ' X ' , ' Y ' , ' Z ' );
 . 19      return  0 ;
 20 is }

 

Guess you like

Origin www.cnblogs.com/liugangjiayou/p/11595259.html