Introduction to Tower of Hanoi
Tower of Hanoi is mathematical puzzle/problem. The goal of the puzzle is to move all the disks from source to destination, adhering to the following rules:
Rule-1: Move only one disk at a time.
Rule-2: A larger disk may not be placed on the top of a smaller disk.
Rule-3: The top disk of any stack can be moved to the top disk of any other stack, with the restriction that you can't move a larger disk on top of a smaller disk.
C program for the Tower of Hanoi
kw.c
Output
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program for the Tower of Hanoi ——————————————————————————————————————————— Enter Number of Disks 3 Move disk 1 from peg A to peg B Move disk 2 from peg A to peg C Move disk 1 from peg B to peg C Move disk 3 from peg A to peg B Move disk 1 from peg C to peg A Move disk 2 from peg C to peg B Move disk 1 from peg A to peg B ——————————————————————————————————————————— kodingwindow@kw:~$
What Next?
C program to find the factorial of a given number
C program to find the factorial of a given number using recursion
C program to print the current date and time
Advertisement