Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++: Suppose that the first number of a sequence is x , where x is an integer. Define: a 0 = x ; a n+1

c++:

Suppose that the first number of a sequence is x, where x is an integer.

Define:

a0 = x; an+1 = an / 2 if an is even;

an+1 = 3 X an + 1 if an is odd.

Then there exists an integer k such that ak = 1.

**Instructions**

Write a program that prompts the user to input the value of x.

The program outputs:

The numbers a0, a1, a2, . . . , ak.

The integer k such that ak = 1

(For example, if x = 75, then k = 14, and the numbers a0, a1, a2, ..., a14, respectively, are 75, 226, 113, 340, 170, 85, 256, 128, 64, 32, 16, 8, 4, 2, 1.)

Test your program for the following values of x: 75, 111, 678, 732, 873, 2048, and 65535.

Then, enhance this program from by outputting:

The largest number of the sequence a0 ,a1 ,a2 , ..., ak.

The position of the largest number

For example, for the input sequence: 75, 226, 113, 340, 170, 85, 256, 128, 64, 32, 16, 8, 4, 2, 1, the program output should contain the following:

The largest number of the sequence is 340

The position of the largest number is 4

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

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

3. Is IBMs program really a mentoring program? Why or why not?

Answered: 1 week ago