Question: Write a loop to compute and print terms according to the Collatz conjecture. The Collatz conjecture says the following sequence always terminates at 1 when
Write a loop to compute and print terms according to the Collatz conjecture.
The Collatz conjecture says the following sequence always terminates at 1 when started with a positive integer n:
If n is even, divide n by 2,
If n is odd, multiply n by 3 and add 1.
Your code will take an integer from the user, then print that number and all subsequent terms in this sequence until it terminates. If your user inputs an integer for which the loop does not terminate, you'll be famous!
If your code doesn't terminate because it has an infinite loop, you won't be famous. You'll be just another programmer with a buggy loop ;-/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
