Menu

(Solved) : Hailstone Sequence Starts Positive Integer Integer Even Divide Two Get Next Integer Sequen Q37163977 . . .

A hailstone sequence starts with some positive integer. If thatinteger is even, then you divide it by two to get the next integerin the sequence, but if it is odd, then you multiply it by threeand add one to get the next integer in the sequence. Then you usethe value you just generated to find the next value, according tothe same rules. Write a function named hailstone that takes thestarting integer as a parameter and returns how many steps it takesto reach 1 (technically you could keep going 1, 4, 2, 1, 4, 2, etc.but you will stop when you first reach 1). If the starting integeris 1, the return value should be 0, since it takes no steps toreach one (we’re already there). For example, if the startinginteger is 3, then the sequence would go: 3, 10, 5, 16, 8, 4, 2, 1,and the return value should be 7. The function should just returnthe value, not display it (though of course you can use printstatements during testing and debugging). You cannot use recursion,since we haven’t covered that technique. The file must be named:hailstone.cpp

Expert Answer


Answer to A hailstone sequence starts with some positive integer. If that integer is even, then you divide it by two to get the ne…

OR