Question: WRITE A C PROGRAM FOR THE FOLLOWING: Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable,

WRITE A C PROGRAM FOR THE FOLLOWING:

Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive).

In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.

Consider the following algorithm:

1. input n

2. print n

3. if n = 1 then STOP

4. if n is odd then n 3*n + 1

5. else n n/2

6. GOTO 2

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

It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1, 000, 000 (and, in fact, for many more numbers than this.) Given an input n, it is possible to determine the number of numbers printed before and including the 1 is printed.

Input

Input an integer n, and n will be less than 10,000 and greater than 0. You can assume that no operation overflows a 32-bit integer.

Output

For input integer n, you should output all the sequence of numbers (on the same line and all the numbers should be separated by one space).

Sample Input

22

44

21

Sample Output

22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

21 64 32 16 8 4 2 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!