Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the rule if n is even divide it by 2 otherwise multiply by three and add 1 . For example, if we
Consider the rule if n is even divide it by otherwise multiply by three and add For example, if we apply the rule to then we would get the new value since is odd and On the other hand, if we apply the rule to we get since is even and The Collatz conjecture states that any sequence that starts with a positive integer formed by repeatedly applying the above rule will always reach the number For example Once the number is reached, we'll stop since the following values would be repeating infinitely. We'll call such a sequence, a Collatz sequence.So far, the Collatz conjecture has not been proved or disproved, so it's useful to investigate the outcome for various starting values.Write a program to generate Collatz sequences with a starting value given by the user, to be stored in a value of type unsigned int. Thats like an int but only stores positive integers. The program will output the values obtained until is reached Of course if the Collatz conjecture is false you could get an infinite loop! The length of the sequence will also be given. To avoid integer overflow, include a defined constant LIMIT in your program with the value one billion. If the next value generate exceeds LIMIT then you should stop the loop and print "Limit exceeded!"The user can continue with more starting values until they decide to quit.Below are some sample runs. Your output should match the sample run output EXACTLY when given the same input. Use a dowhile loop for the outer loop to allow the user to enter more starting values and a while loop for the inner loop to generate the sequence No use of the keyword break is allowed.For your submission, copy paste your code and at the bo
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started