C Programming Language (CS2402): HW5

Instructor: J.-S. R. Jang


Due date: Oct. 21, 1996
  1. (30%) Exercise 5.38 (page 199) of Chapter 5. You program should in an loop that gets the number of disks (to be move from peg 1 to 3) from the user. The program stops whenever the given number of disks is less than or equal to 0. A sample output list (with italic user input) is as follows:
    Please enter the no. of disks to be moved from peg 1 to 3: 3
    1 --> 3
    1 --> 2
    3 --> 2
    1 --> 3
    2 --> 1
    2 --> 3
    1 --> 3
    Please enter the no. of disks to be moved from peg 1 to 3: 4
    1 --> 2
    1 --> 3
    2 --> 3
    1 --> 2
    3 --> 1
    3 --> 2
    1 --> 2
    1 --> 3
    2 --> 3
    2 --> 1
    3 --> 1
    2 --> 3
    1 --> 2
    1 --> 3
    2 --> 3
    Please enter the no. of disks to be moved from peg 1 to 3: 2
    1 --> 2
    1 --> 3
    2 --> 3
    Please enter the no. of disks to be moved from peg 1 to 3: 0
    Thank you for playing the Towers of Hanoi!