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_x000D_ 65 196 98 49 148_x000D_ 74 37 112 56 28_x000D_ 14 7 22 11 34_x000D_ 17 52 26 13 40_x000D_ 20 10 5 16 8_x000D_ 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_x000D_ 13 40 20 10 5_x000D_ 16 8 4 2 1_x000D_
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 firstname.lastname@example.org)
yEd Graph Editor
We always make sure that our academic writers follow all your instructions precisely. You can choose your academic level and we will assign a writer who has a respective degree.
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document.
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. Otherwise a 100% refund is guaranteed.
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. We also promise maximum confidentiality in all of our services.
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Whether you have an urgent deadline or those that have time. You can take some time and relax after trusting us with your paper. We make sure that we conduct the academic writing services diligently.
Among the wide variety of academic work, essay writing is one of the simplest a student can ever come across. Usually, it is a task which students encounter and learn how to write whilst in high school. However, the case is quite different when it comes to university and college.
Are you looking for an online writing firm that can offer you reliable custom term paper writing help? Is your wish and desire to get someone who can guide you throughout the process of writing term papers? If yes, then you have come to the right place.
Coursework is essential for every student in order to graduate from college. However, most of it is deadline-centric, and that becomes a challenge to most learners. With the amount of work, learners are receiving every day, finding time to work on every task is not easy.
Online homework help services are an answer to every challenge that students go through. Despite the difference in the needs and levels of learning, all students can benefit from these services. Acemyhomework is one of the best online homework help service companies you can find on the internet.