The tower of Hanoi is a famous problem in which we have three rods and n disks. The aim of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

- Only one disk can be moved at a time.
- Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
- No bigger disk may be placed on top of a smaller disk.

Now let us discuss our approach to this problem

We have 3 discs as shown in the figure. Now in each step we only move 1 discs

First step disc red →C

Second step disc blue →B

Third step disc red →B

Fourth step disc green →C

fifth step move red disc→A

sixth step move blue disc→C

seventh step move red disc →C

And we have successfully moved all discs to rod C

Based on your knowledge try to write a C++ program to solve this problem.

Hint: make use of recursion.

Solution: