Advertisement
mssroot

Hanoi

Dec 11th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. void print_move( int from,int to )
  6.  
  7. {
  8.  
  9.     cout<<"Move Disk From "<<from<< " To "<<to<<endl;
  10.  
  11. }
  12.  
  13.  
  14.  
  15. void transfer ( int from,int to,int via,int n )
  16.  
  17. {
  18.  
  19.     if(n==1)
  20.  
  21.     {
  22.  
  23.         print_move(from,to);
  24.  
  25.     }
  26.  
  27.     else
  28.  
  29.     {
  30.  
  31.         transfer(from,via,to,n-1);
  32.  
  33.         print_move(from,to);
  34.  
  35.         transfer(via,to,from,n-1);
  36.  
  37.     }
  38.  
  39. }
  40.  
  41.  
  42.  
  43. void main(int k,char**s)
  44.  
  45. {
  46.  
  47.     if(k>1&&atoi(s[1]))
  48.  
  49.     {
  50.  
  51.         transfer( 1,3,2,atoi(s[1]));
  52.  
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement