944,017 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 45768
  • C RSS
Nov 13th, 2005
0

Towers of Hanoi(Recursion)

Expand Post »
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4. void hanoi(int x, char from,char to,char aux)
  5. {
  6.  
  7. if(x==1)
  8. {
  9. printf("Move Disk From %c to %c\n",from,to);
  10. }
  11. else
  12. {
  13. hanoi(x-1,from,aux,to);
  14. printf("Move Disk From %c to %c\n",from,to);
  15. hanoi(x-1,aux,to,from);
  16. }
  17.  
  18. }
  19. void main()
  20. {
  21. int disk;
  22. int moves;
  23. clrscr();
  24. printf("Enter the number of disks you want to play with:");
  25. scanf("%d",&disk);
  26. moves=pow(2,disk)-1;
  27. printf("\nThe No of moves required is=%d \n",moves);
  28. hanoi(disk,'A','C','B');
  29. getch();
  30. }
Last edited by Nick Evan; Dec 30th, 2009 at 5:09 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chinjoo is offline Offline
3 posts
since Nov 2005
Nov 13th, 2005
0

Re: Towers of Hanoi(Recursion)

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 13th, 2005
0

Re: Towers of Hanoi(Recursion)

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!
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Dec 18th, 2008
-1
Re: Towers of Hanoi(Recursion)
thanks for the program ...its g8 with few errors which can b corrected easily
Reputation Points: 10
Solved Threads: 0
Newbie Poster
raftinga is offline Offline
1 posts
since Dec 2008
Dec 24th, 2008
0

Re: Towers of Hanoi(Recursion)

If you full code in correct format you can add in the code snippets rather posting on the forum
Thanks!!
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008
Jan 17th, 2011
0
Re: Towers of Hanoi(Recursion)
i am still in confusion in TOH recursive function how line number 13 and 15 executes both of them executes concurrently or what??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yash00yash is offline Offline
1 posts
since Jan 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Determinant
Next Thread in C Forum Timeline: The Return Oriented Programming Hackers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC