Question: Write a MATLAB program for the following: Collatz Conjecture game: Ask the user to enter a positive integer N. If N is odd, multiply it

Write a MATLAB program for the following:

Collatz Conjecture game: Ask the user to enter a positive integer N. If N is odd, multiply it by 3 and add 1 to it. If N is even, divide it by 2. Keep repeating this procedure until N = 1. The Collatz conjecture is that for any input value N, the final result is N=1. This has not yet been proved mathematically, but no number has been found for which this is not true.Use a while loop to implement the rules described above. The program should display the intermediate values of N (as a sequence separated by commas) and also return the number of steps needed for N to become 1. Test your program with N = 3.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!