Answered step by step
Verified Expert Solution
Question
1 Approved Answer
USING C CODE A complete description of the Towers of Hanoi problem is found in problem 5.36, p. 208 of the Deitel text book (8h
USING C CODE
A complete description of the Towers of Hanoi problem is found in problem 5.36, p. 208 of the Deitel text book (8h edition). A scan of that problem will be provided below for those who don't have the book. Your task: Implement the Towers of Hanoi solution using the recursive method described in the book. As the book suggests, you should use a recursive function with four input parameters. Have your program get the following information from the user: 1) The number of disks to be moved. 2) The peg the disks are currently on, i.e., the "current" peg. 3 The peg to which we wish to move the disks, i.e, the "target" peg. Your program will thereafter assume that the third peg, i.e., the one not mentioned in steps (2) and (3) above, will be used as the temporary storage peg. (Your program needs to calculate this.) Test your program on several values for the number of pegs to be moved, for example: 3, 5, 8, and 10. As described in the book, your program should print out the exact set of instructions necessary to move the selected number of disks from the current peg to the target peg. In addition to the above, include a counter that counts the number of moves printed. Include a report at the end that reveals this number. For some sample runs: Now moving 3 disks from Peg 1 to Peg 3: 1, 2, 3, 4, 5, 6, 7, 1-> 3 1-> 2 Move #: Move #: Move #: Move #: Move#: Move#: Move #: Hove: Move: Move: 3- 2 Move : Move: Move: 2->3 Move: 1->3 2->1 1->3 Move Count7 Now moving 4 disks from Peg 2 to Peg 1: 2-> 3 Move #: Move#: Move#: Move #: Move: 1, 2, 3, 4, Move: 2 -1 3->1 Move: Hove: 2-> 3Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started