Syracuse Sequence
The Syracuse (also called Collatz or Hailstone) sequence is
generated by starting with a natural number and repeatedly applying the
following function until reaching 1:
syr(x) = | x/2 | if x is even
|
| 3x + 1 | if x is odd
|
For example, the Syracuse sequence starting with 5 is: 5, 16, 8, 4, 2, 1.
Write a program that gets a starting value from the user and then prints
the Syracuse sequence for that starting value.
The program may run as follows.
Input a natural number -- 11
11 34 17 52 26 13 40 20 10 5 16 8 4 2 1