Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

fill in sheet: PART 4: Collatz Sequence (www.projecteuler.net) (25 points) This problem is to get you used to using C++ to solve simple problems. The

image text in transcribed

fill in sheet:

image text in transcribed

PART 4: Collatz Sequence (www.projecteuler.net) (25 points) This problem is to get you used to using C++ to solve simple problems. The following iterative sequence is defined for the set of positive integers: n = n/2 (if n is even, divide it by 2) n 3n+ 1 (if n is odd, then multiple it by 3 and then add one) For example, using the rules above and starting with 13, we generate the following sequence: 13 -> 40 -> 20-> 10-> 5 -> 16 -> 8 -> 4->2 -> 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. Write a program that continuously prompts the user for a positive integer (unsigned int) and then outputs the terms in the format shown below, until the term with a value of 1 is reached. Limit the number of terms per line to 10. If more than 10 terms, then start on a new line. The program exits when the user enters 0. Please enter a positive number (0 to exit): 13 Terms: 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 Total number of terms: 10 Please enter a positive number ( to exit): -3 Error! Please enter a positive number (0 to exit): 0 Bye! Part 4: COLLATZ SEQUENCE - In addition to submitting your source code, enter the results below: Assuming an input value of n=21 what is the total number of terms and the sequence of terms: # terms: Values of Terms

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions