3n+1, C/C++ Programming

Assignment Help:
Consider the following algorithm to generate a sequence of numbers. Start with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this process with the new value of n, terminating when n is equal to 1. For example, the following sequence is generated for n = 22:

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

It is conjectured (but not yet proven) that this algorithm will terminate at n is equal to 1 for every integer n. The conjecture holds for integers up to at least 1,000,000.

For an input n, the cycle-length of n is the number of numbers generated up to and including the 1. In the example above, the cycle length is 16.

Write a C++ program that repeatedly prompts the user for two numbers, Start and End, and determines the maximum cycle length over all numbers between Start and End, including both endpoints. Assume all inputs are integers less than 1,000,000 and greater than 0. If a negative number is entered for the start, then the program should end immediately.

Sample Command Line Interface: (Bold Signifies User Input)
Start: 1
End: 10
Max: 20

Start: 100
End: 200
Max: 125

Start: 201
End: 210
Max: 89

Start: -3

Related Discussions:- 3n+1

How does a structure differ from an array, Question : (a) What is a str...

Question : (a) What is a structure? Provide a simple example of your own to illustrate this feature. (b) How does a structure differ from an array? (c) Describe a structu

Explain function overloading, Function Overloading Function overloading...

Function Overloading Function overloading is a form of polymorphism. Function overloading facilitates explaining one function having many forms. In other words it facilitates e

Tree, Write algorithm and program for the conversion of a Tree to a Binary ...

Write algorithm and program for the conversion of a Tree to a Binary Tree

Program to create a class and store student information, Develop a Student ...

Develop a Student class that has the following header file: #ifndef STUDENT_H #define STUDENT_H #include #include #include using namespace std; class Stu

Main program to test the basic operations, The Main program is slightly mor...

The Main program is slightly more complicated and you need to think about the I/O process. First of all, for most applications you do not call the low level routines GetChar and P

Explain difference between early binding and late binding, What is the diff...

What is the difference between early binding and late binding? What are advantages of early binding? a.) Late binding refers to function calls which aren't resolved until run t

Cipher: Decrypt and Encrypt, You must write a program that can both decrypt...

You must write a program that can both decrypt and encrypt a single word that is entered by the user. The initial choice of encryption and decryption is left up to the user. Addi

Get reverse engineer to linux game routine analysis, Get Reverse Engineer t...

Get Reverse Engineer to Linux game routine analysis Project Description: I want a fast and efficient reverse engineer with good knowledge of assembly x86 language, strong rev

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd