Write a program to print out Collatz sequence for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows: If previous number is odd, the next number is 3 times the previous, plus 1. If previous number is even, the next number is half of the previous
According to Collatz proposition, the sequence ultimately reaches 1 no matter what the starting number is.
Your program should print out all numbers in the sequence down to 1. At the end, display number of iterations it took to arrive at 1, and average of all values in sequence. For prettier output, insert a line break after printing every five numbers, align the numbers in columns and format the average value to two decimal places.
After printing a Collatz sequence, your program should ask the user if they want to print out another sequence. The loop will continue until user decides to quit.
Review the sample run below to clearly understand all requirements.
Enter a positive number, or zero to quit: 57
172 86 43 130
65 196 98 49 148
74 37 112 56 28
14 7 22 11 34
17 52 26 13 40
20 10 5 16 8
4 2 1
It took 32 iterations to arrive at 1. The average value is 51.66
Enter the next positive number, or zero to quit: 11
11 34 17 52 26
13 40 20 10 5
16 8 4 2 1
It took 14 iterations to arrive at 1.
The average value is 18.50
Enter the next positive number, or zero to quit: 0
Have a nice day!
Your submission must consist of following tasks: Task 1 Draw a flowchart that presents the steps of the algorithm required to perform the task specified. You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission, as long as the handwriting is clear and legible. However, it is strongly recommended to draw flowcharts using a drawing software. Here are links to some free drawing tools
Draw.io Lucidchart with an education account (register using your_csu_id@postoffice.csu.edu.au)
yEd Graph Editor
Pencil Project