1,105,384 Community Members

Towers of Hanoi(Recursion)

Member Avatar
Chinjoo
Newbie Poster
3 posts since Nov 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
#include<stdio.h>
#include<conio.h>
#include<math.h>
void hanoi(int x, char from,char to,char aux)
{

if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}

}
void main()
{
 int disk;
 int moves;
 clrscr();
 printf("Enter the number of disks you want to play with:");
 scanf("%d",&disk);
 moves=pow(2,disk)-1;
 printf("\nThe No of moves required is=%d \n",moves);
 hanoi(disk,'A','C','B');
 getch();
 }
Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 80 [?]
Team Colleague
 
0
 

Please stop posting poorly formated non-standard code for no reason at all. If you insist on spamming the forum with pointless threads, I'll delete them without hesitation.

Member Avatar
Dani
The Queen of DaniWeb
20,552 posts since Feb 2002
Reputation Points: 1,356 [?]
Q&As Helped to Solve: 927 [?]
Skill Endorsements: 204 [?]
Administrator
Featured
Sponsor
 
0
 

If you are so inclined to contribute fully-working code snippets, they would be most appreciated in our code snippet library @ www.daniweb.com/code/ - not the forums.

Thanks!

Member Avatar
raftinga
Newbie Poster
1 post since Dec 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

thanks for the program ...its g8 with few errors which can b corrected easily

Member Avatar
ajay.krish123
Junior Poster in Training
90 posts since Nov 2008
Reputation Points: -4 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 0 [?]
 
0
 

If you full code in correct format you can add in the code snippets rather posting on the forum
Thanks!!

Member Avatar
yash00yash
Newbie Poster
1 post since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i am still in confusion in TOH recursive function how line number 13 and 15 executes both of them executes concurrently or what??

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article