Tower of hanoi is a historical problem, which can be easily expressed using recursion. There are N disks of decreasing size stacked on one needle, and two other empty needles. Tower of hanoi is required to stack all the disks onto a second needle in the decreasing order of size. The third needle can be used as a temporary storage. The movement of the disks must confirm to the following rules, 1. Only one disk may be moved at a time /* Program of towers of hanoi. */ #include <> void move ( int, char, char, char ) ; void main( ) clrscr( ) ; move ( n, ‘A’, ‘B’, ‘C’ ) ; getch( ) ; void move ( int n, char sp, char ap, char ep )
2. A disk can be moved from any needle to any other.
3. The larger disk should not rest upon a smaller one.
#include <>
{
int n = 3 ;
}
{
if ( n == 1 )
printf (“\nMove from %c to %c “, sp, ep ) ;
else
{
move ( n – 1, sp, ep, ap ) ;
move ( 1, sp, ‘ ‘, ep ) ;
move ( n – 1, ap, sp, ep ) ;
}
}
Labels
- ajax (1)
- Assembly Programming (3)
- Books on C++ (6)
- C Programs (35)
- Challenging Question (1)
- Class (1)
- Complete Script (1)
- Computer Graphics (1)
- CSS (2)
- Datastructure (6)
- Download (3)
- e-books (8)
- Errors (1)
- FTP (2)
- HTML (3)
- Interview Questions (8)
- Introduction (1)
- Methods (2)
- OOP (1)
- Operator Overloading (1)
- Operators (1)
- Others (5)
- PHP (4)
- PHP Errors (1)
- PHP Script (1)
- Programming (3)
- Question Bank (6)
- Short Questions (1)
- SQL (1)
- Tips (1)
- Tricks (1)
- Tricky Programs in C (2)
- Useful Scripts (1)
- WAP (1)
- Web (3)
- XHTML (1)
Tower Of Hanoi in c
Sunday, August 29, 2010Posted by Xofth at 10:35 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment