Tower of Hanoi without Recursion C Program

C Program To Solve Tower of Hanoi without Recursion

Learn How To Solve Tower of Hanoi without Recursion in C Programming Language. This Non Recursive C Program makes use of an Iterative method using For Loop to solve Tower of Hanoi Problem. The Tower of Hanoi Algorithm in Data Structures is a very famous Interview Question for Beginners. The C Program For Tower of Hanoi Program using Iteration can be solved by using For, While and Do While Loop.


To know more about Tower of Hanoi, you can read this guide: Tower of Hanoi Problem in C Programming

If you try to compile this C Program for Tower of Hanoi without using Recursion in Linux, you will get the following error:

This is because the pow() method cannot be found in the library files. To overcome this error, you will have to explicitly include the math.h header file. Compile the program using the following command:


Also Read: Tower of Hanoi in C using Recursion

C Program To Solve Tower of Hanoi without Recursion

Must Read: C Program For FCFS Algorithm

Output

C Program To Solve Tower of Hanoi without Recursion and Iterative For Loop

If you have any compilation errors or doubts in this C Program for Tower of Hanoi without Recursion, let us know about in the Comment Section below.

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

5 thoughts on “Tower of Hanoi without Recursion C Program

  • August 1, 2016 at 12:42 am
    Permalink

    Here’s another method to solve the Tower of Hanoi puzzle.

    It’s a mechanical solution which doesn’t use recursion. Try it out using
    3 or 4 coins of different sizes.

    Arrange the three rods to form a triangle.

    Starting position (where X, Y and Z are different size coins):

    empty rod

    Z
    YYY
    XXXXX

    starting rod destination rod

    Finished position:

    empty rod

    Z
    YYY
    XXXXX

    starting rod destination rod

    Move the smallest disk on every other turn — always in the same
    direction. On the remaining turns make the only valid move that does
    not involve the smallest disk.

    The following rule will make sure that the tower of disks end up on the
    third rod: If the number of disks in the puzzle is an odd number then
    always move the smallest disk counter-clockwise around the triangle; if
    the number of disks in the puzzle is an even number then always move the
    smallest disk clockwise around the triangle.

    With this solution the even numbered disks move around the triangle in
    one direction while the odd numbered disks move around the triangle in
    the opposite direction.

    Reply
    • August 1, 2016 at 11:31 pm
      Permalink

      Thanks a lot for providing us a different angle to Tower of Hanoi Problem in C Language.

      Reply
  • August 19, 2016 at 1:01 am
    Permalink

    I think Recursion is much better instead of iterations since the recursive tower of hanoi algorithm is much simple to understand and looks efficient as well.

    Reply
  • September 9, 2016 at 10:44 pm
    Permalink

    Tower of Hanoi with Iteration method is much more understandable than the Recursive approach. Thanks!

    Reply
  • September 14, 2016 at 11:40 am
    Permalink

    Thanks for the code iterative code for Tower of Hanoi. Thanks

    Reply

Join The Discussion