Answered step by step
Verified Expert Solution
Question
1 Approved Answer
or/while loops and if/else statements. This assignment will further expose you to C control structures, specifically f What to do Write a C program that
or/while loops and if/else statements. This assignment will further expose you to C control structures, specifically f 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-> 22 11-> 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 run it on all natural numbers, starting at 1, up to and including some value MAX. I 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 iterations it took to eventually reach 1 What to submit I ask you to submit the following The source code of your program. A screen shot that demonstrates the proper working of your program, when it is run on numbers between 1 and 30 (ie, #define MAX 30) To see what I'm shooting for, here the the output of my program for runs of numbers between 1 and 20 7-16 9 19
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