For this question, you will write a program that prompts the user to enter an integer value between 1 and 1000 (exclusive). Your program should then print out a sequence of numbers between the given value and 1 (inclusive) following the pattern below: For a given number ai, If ai is even, then ai+1 = floor(ai / 2) If ai is odd, then ai+1 = 3ai + 1 Your program should stop printing numbers once the sequence reaches the value of 1. If the user enters a number that is not between 1 and 1000 (exclusive), print "Invalid input." and prompt the user for a number again. This sequence is referred to as the Collatz sequence. The Collatz Conjecture states that this sequence will eventually reach the value of 1 for any starting number, a fact that has not yet been proven by modern mathematics! Note: floor(x) means that x should be rounded down to the nearest integer.
For this question, you will write a
For a given number ai,
- If ai is even, then ai+1 = floor(ai / 2)
- If ai is odd, then ai+1 = 3ai + 1
Your program should stop printing numbers once the sequence reaches the value of 1.
If the user enters a number that is not between 1 and 1000 (exclusive), print "Invalid input." and prompt the user for a number again.
This sequence is referred to as the Collatz sequence. The Collatz Conjecture states that this sequence will eventually reach the value of 1 for any starting number, a fact that has not yet been proven by modern mathematics!
Note: floor(x) means that x should be rounded down to the nearest integer.


Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









