Question: 7. If you take a positive integer, halve it if it is even or triple it and add one if it is odd, and repeat,

 7. If you take a positive integer, halve it if it
is even or triple it and add one if it is odd,

7. If you take a positive integer, halve it if it is even or triple it and add one if it is odd, and repeat, then the number will eventually become one. Warning: it may take a long t points) me! (9 Set up a loop containing a statement to read in a number (input terminated by zero) and to print out the sequence obtained from each input. The number 13 is considered to be very unlucky and if it is obtained as part of the sequence then execution should immediately terminate with an appropriate message. Demonstrate that your program works by outputting the sequences generated by the following numbers: 5 100 Test runs of the code are shown below

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!