Question

5.1 Collatzs hypothesis- 6 points In 1937, a mathematician named Lothar Collatz e formulated an intriguing hypothesis (aka. Collatz conjecture e ) that remains unsolved to this day (perhaps this would be a good challenge for you?) which can be described in the following way: 1. take any non-negative and non-zero integer number and name it cO; 2. if its even, evaluate a new cO as cO/2 3. otherwise, if its odd, evaluate a new cO as 3 cO+1 4. if cO 1, skip to point 2 The hypothesis says that, regardless of the initial value of cO, it will always (always!) go to 1 Of course, its an extremely complex task to use a computer in order to prove the hypothesis for any natural number (it may in fact need artificial intelligence), but you can use C++ to check some individual numbers. Maybe you can find the one that disproves the hypothesis and become a famous mathematician Given the above scenario, write a program which reads one natural number and executes the above steps as long as co remains different from 1 Moreover, well give you another task - we want you to count the steps needed to achieve the goal. Your code should output all intermediate values of cO, too - itll be very illustrative, wont it? Hint: the most important part of the problem is how to transform Collatzs idea into a while loop- this is the key to success Input validation: Do not accept a zero or negative value for the initial input. Include appropriate volidation routines If this happens, include a validation routine that clears the error state and allows the user to input a positive value. number Sample screen output 1: Enter a non negative number greater than 0: 15 46 70 35 106 53 160 e0 40 20
media%2F8d9%2F8d915c9e-0f02-4270-8a70-e0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include<iostream>

using namespace std;

int main(){

int c0;

while(1){

cout<<"Enter a non negative number greater than 0: ";

cin>>c0;

if(c0>0)

break;

cout<<"Invalid value input"<<endl;

}

int steps = 0;

while(c0!=1){

if(c0%2==0)

c0 = c0/2;

else

c0 = 3*c0 +1;

steps++;

cout<<c0<<endl;

}

cout<<"steps = "<<steps<<endl<<endl;

return 0;

}

Add a comment
Know the answer?
Add Answer to:
5.1 Collatz's hypothesis- 6 points In 1937, a mathematician named Lothar Collatz e formulated an intriguing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Name: Section Number To be graded assignments must be completed and submitted on the original book...

    Name: Section Number To be graded assignments must be completed and submitted on the original book page Hypothesis Testing -As a Diagnostic Test ? Answer the following questions over the content material you just read or watched. 1. What is a false positive rate in the context of hypothesis testing? 2. What is the goal of hypothesis testing? 3. What is a Type I error, and how is it related to an "alpha level?" 4. What does it mean to...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

  • Discussion questions 1. What is the link between internal marketing and service quality in the ai...

    Discussion questions 1. What is the link between internal marketing and service quality in the airline industry? 2. What internal marketing programmes could British Airways put into place to avoid further internal unrest? What potential is there to extend auch programmes to external partners? 3. What challenges may BA face in implementing an internal marketing programme to deliver value to its customers? (1981)ǐn the context ofbank marketing ths theme has bon pururd by other, nashri oriented towards the identification of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT