Cycle Length of Syracuse Sequence
- Consider the
Syracuse Sequence defined in a previous
exercise.
- Given the input 22, the following sequence of numbers will be
printed
- 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
- The number of numbers printed (including the 1) is called the
cycle length of a given input n.
- For n = 22, the cycle length is 16.
- Design a program which requests the user to input an integer n,
and then calculate the cycle length of 1, 2, 3, ..., n as follows.
Input a number -- 22
1:1
2:2
3:8
4:3
5:6
6:9
7:17
8:4
9:20
10:7
11:15
12:10
13:10
14:18
15:18
16:5
17:13
18:21
19:21
20:8
21:8
22:16