Question: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: If the value is even, halve
Write a program that prompts the user to enter a positive integer value, and compute the following sequence: If the value is even, halve it. If it's odd, multiply by 3 and add 1. Repeat this process until the value is 1., printing out each value Finally print out how many of these operations you performed. . Note: If the input value is less than 1., print a message containing the word Error and exit the program. You can assume that the input will have smaller than 200 operations. This is how the output should look like: . Initial value 18: 9 Bext valde 18: 28 Hext value is: 14 Next value ist liext value 18: 2ext value MO M Next value Le: 35 Next value is: 17 Next value an: 52 Next value La: 26 Next value is: 13 Next value is: 40 Next value is: 201 Next value is: 10 Next value is: 5 Next value is: 16 Next value is: 8 Next value is: 4 Next value is: 2 Final value 1, number of operations performed 19
Step by Step Solution
3.46 Rating (146 Votes )
There are 3 Steps involved in it
mainpy 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 try initialvalue intinputInitial value is if ... View full answer
Get step-by-step solutions from verified subject matter experts
