Write a script that asks for an Integer (n) and then computes the following base
ID: 3141406 • Letter: W
Question
Write a script that asks for an Integer (n) and then computes the following based on the value of the Integer: While the value of n is greater than 1, replace the integer with half of Its value (n/2)lf the Integer is even. otherwise, replace the Integer with three times its value, plus 1 (3 * n+1). Make provision to count the number of values in (or the length of the sequence that results. Example calculation: If n = 10, the sequence of Integers is 5, 16, 8, 4, 2, 1 and so the length is 6. Make a plot of the length of the sequence that occurs as a function of the integers from 2 to 30. For in example, when n = 10, the length is 6 while for n = 15, the length is 17. Is there any pattern? Try larger numbers to see if any pattern occurs. Is there any integer for which the sequence does not terminate?Explanation / Answer
Hope u got the answer,if u have any problem comment in here i will reply.
Thank you
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.