Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Define marketing.

Answered: 1 week ago

Question

What are the traditional marketing concepts? Explain.

Answered: 1 week ago

Question

Define Conventional Marketing.

Answered: 1 week ago

Question

Define Synchro Marketing.

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago