Write a C++ program for the given instructions: Summary 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:

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.2: The If-else Statement
Problem 3E
icon
Related questions
Question

Write a C++ program for the given instructions:

Summary

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

Define:

  • a0 = xan+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:

  1. The numbers a0a1a2, . . . , ak.
  2. The integer k such that ak = 1

(For example, if x = 75, then k = 14, and the numbers a0a1a2, ..., a14, respectively, are 75226113340170852561286432168421.)

Test your program for the following values of x751116787328732048, and 65535.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 7 images

Blurred answer
Knowledge Booster
Bare Bones Programming Language
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr