Question
Instructions Write a C++ program that repeatedly does the following. Input a positive integer from the user and print the Collatz sequence starting at that
Instructions Write a C++ program that repeatedly does the following. Input a positive integer from the user and print the Collatz sequence starting at that integer, with items separated by blanks and followed by a newline. For example, if the user types 3, then the program should print 3 10 5 16 8 4 2 1 If the user types 2, then the program should print 2 1 If the user types 1, then the program should print 1 If the user types 60, then the program should print 60 30 15 46 23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1 The source code for your program should be contained in a single file named collatz.cpp. The program should check whether the number the user types is positive. If it is not, the program should notify the user and give an opportunity to redo the input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started