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.3: Nested If Statements
Problem 7E
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning