Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago