Answered step by step
Verified Expert Solution
Question
1 Approved Answer
What to do Write a C program that implements the 3A+1 algorithm. This algorithm works like so: starting with a given integer number, the algorithm
What to do Write a C program that implements the "3A+1" algorithm. This algorithm works like so: starting with a given integer number, the algorithm determines whether the number is odd or even. If it is odd, it computes 3 times the original number plus one, as the name 3A+1 suggests. If the number is even, it is divided by 2. In either case, the result is being assigned back to the variable that contained the original number. The process keeps going until a result of 1 is achieved, at which point the algorithm terminates. Interesting fact: although this algorithm is very simple to explain, and run, nobody could ever prove that it actually terminates. For our purposes we just assume it does! Here is a sample run of the algorithm for an initial number of 7 7- 2211 34 - 17 -52-26- 13- 40->20- 10->5-> 16-8-4-2->1 As you can see, the algorithm ran though 16 iterations until it reached 1. In your implementation of the algorithm I want you to un it on all natural numbers, starting at 1, up to and including some value MAX. ask you to implement MAX as a symbolic constant using a #denne preprocessor directive. For each run, you are supposed to print out the original number and how many terations it took to eventually reach1
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