Professional web hosting - Chapter 6 Methods 235 a) Move n

Chapter 6 Methods 235 a) Move n 1 disks from peg 1 to peg 2, using peg 3 as a temporary holding area. b) Move the last disk (the largest) from peg 1 to peg 3. c) Move the n 1 disks from peg 2 to peg 3, using peg 1 as a temporary holding area. The process ends when the last task involves moving n = 1 disk (i.e., the base case). This is accomplished by trivially moving the disk without the need for a temporary holding area. Write a program to solve the Towers of Hanoi problem. Allow the user to enter the number of disks in a TextBox. Use a recursive Tower method with four parameters: a) The number of disks to be moved b) The peg on which these disks are threaded initially c) The peg to which this stack of disks is to be moved d) The peg to be used as a temporary holding area Your program should display in a read-only TextBoxwith scrolling functionality the precise instructions for moving the disks from the starting peg to the destination peg. For example, to move a stack of three disks from peg 1 to peg 3, your program should print the following series of moves: 1 . 3 (This means move one disk from peg 1 to peg 3.) 1 . 2 3 . 2 1 . 3 2 . 1 2 . 3 1 . 3 6.16 The greatest common divisor of integers x and y is the largest integer that evenly divides both xand y. Write a recursive method Gcd that returns the greatest common divisor of xand y. The Gcdof x and y is defined recursively as follows: If yis equal to 0, then Gcd(x, y)is x; otherwise, Gcd(x,y)is Gcd(y,x%y), where %is the modulus operator.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply