Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Tower of Hannoi (http://www.go4expert.com/forums/tower-of-hannoi-t1979/)

saomcol 23Nov2006 20:03

Tower of Hannoi
 
How can I write a prog to implement the Tower of Hannoi

shabbir 23Nov2006 22:02

Re: Tower of Hannoi
 
Code:

#include <stdio.h>
#include <conio.h>

void diskchange(char l,char r,char c,int n)
{
        if(n>0)
        {
                diskchange(l,c,r,n-1);
                printf("\nMove %d from %c to %c\n",n,l,r);
                diskchange(c,r,l,n-1);
        }
}

int main()
{
        int n;
        printf("\nEnter the number of disks\n");
        scanf("%d",&n);

        diskchange('L','R','C',n);
        printf("\nPress any key to exit\n");
        getch();

        return 0;
}


sharma_atul13 17Jul2007 17:52

Re: Tower of Hannoi
 
I keenly want to know wat is this tower of hannoi???

shabbir 17Jul2007 18:08

Re: Tower of Hannoi
 
The Tower of Hanoi is a mathematical game or puzzle which consists of three (n) pegs, and a number of discs of different sizes which can slot onto any peg. The puzzle starts with the discs neatly stacked in order of size on one peg, smallest at the top and moving them to the other peg using the third peg. Condition is at no move you will have the larger peg over the smaller one.

shabbir 17Jul2007 18:10

Re: Tower of Hannoi
 
Good sample at wikipedia
http://upload.wikimedia.org/wikipedi...of_Hanoi_4.gif


All times are GMT +5.5. The time now is 05:23.