Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program in C. Please try to find the formula for the number of moves for n disks as well. thank you. Program 2-Towers of Hanoi

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Program in C. Please try to find the formula for the number of moves for n disks as well. thank you.

Program 2-Towers of Hanoi A complete description of the Towers of Hanoi problem is found in problem 5.36, p. 208 of the Deitel text book (8th edition). A scan ofthat 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" pe 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 Move 1, Move 3 Move 2, Move 2 Move 3, Move 3 2 Move 4, Move 3 Move 5, Move 1 Move 6, Move 3 Move 7, Move 1 3 Move Count 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions