C++ Programming Tutorial

 
 
 
 

Image

 # include <iostream.h>
 # include    <conio.h>

 void move(const int n,const int fromTower,
                    const int toTower,const int spareTower)
 {
    if(n>0)
    {
       move((n-1),fromTower,spareTower,toTower);

       cout<<\"\\t Move the Top Disk from Tower-\"<<fromTower
                          <<\" to Tower-\"<<toTower<<\"\\n\";

       move((n-1),spareTower,toTower,fromTower);
    }
 }

 int main( )
 {
    clrscr( );

    cout<<\"\\n\\t **************   TOWERS OF HANOI   **************\\n\"<<endl;
    cout<<\"\\t The Mystery of Towers of Hanoi is as follows : \\n\"<<endl;

    move(4,1,3,2);

    cout<<\"\\n\\t *************************************************\";

    getch( );
    return 0;
 }

 
 
Didn't find what you were looking for? Find more on Program to solve the Towers of Hanoi Problem (using Recursive Algorithm)