Question: C++ coding help Write a program that prompts the user for a positive integer, the first term in a hailstone sequence, and then generates a

C++ coding help

Write a program that prompts the user for a positive integer, the first term in a hailstone sequence, and then generates a subsequence from that hailstone number to the next occurrence of 1 in the sequence. The program should also determine and display the sum and length of the subsequence. If the user enters an integer less than 1, the program should display an error message as shown in the sample run. In order for the program to handle large integers, use long rather than int when declaring them.

C++ coding help Write a program that prompts the user for a

Definition 1. The Collatz Conjecture, also known as the 3n+1 problem, proposed by Lothar Collatz in 1937 hypothesizes that given any positive integer n the sequence below always reaches 1. t(n + 1) = { 3t(n) +1 t(n) is odd t(n)/2 otherwise Definition 2. Sequences of integers generated in the Collatz problem are called hailstone sequences. They are called so because the values typically rise and fall, somewhat analogously to a hailstone inside a cloud. For exam- ple, for a starting number of t(1) = 7, the sequence is 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1

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!