Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Program In this lab, you will practice the technique of nesting structures, as well as the use of the logical operators, to implement a

C# Program

In this lab, you will practice the technique of nesting structures, as well as the use of the logical operators, to implement a solution to a slightly more complex problem than those of the previous labs This is the first lab designed to help you strengthen your skills of algorithm design, and I highly recommend using the pseudocode and/or flowcharting techniques discussed in the lecture to do so.

Your Program

The Collatz Conjecture is a conjecture in mathematics that concerns a sequence sometimes known as hailstone numbers. Given any positive integer n, the following term, n+1 is calculated as follows:

If n is even, then n+1 is defined as n/2.

If n is odd, then n+1 is defined as 3n + 1

The Collatz Conjecture states that, for any value of n, the sequence will always reach 1. Once the pattern reaches 1, it repeats indefinitely (3 * 1 + 1 = 4, 4/2 = 2, 2/2 = 1)

For your lab, you will write a program to calculate and display the sequence of hailstone numbers from any initial starting point, n, until it reaches 1. After the sequence terminates at 1, you should print out the number of steps that were required to reach that point.

The value of n should be initialized by the user. Use a while loop to validate the users input and make sure it is a positive integer value between 2 and 1000.

To calculate the sequence, you will need to nest selection structures inside of a loop that runs until n has reached the ending value of 1. To determine if a number is even or odd, we can calculate the remainder with a modulus of 2. If n % 2 equals 0, then n is an even number. Else, if n % 2 equals 1, then n is odd.

After calculating the sequence and displaying the result, prompt the user to enter Y or N to indicate if they would like to calculate the sequence for another value. As long as they dont answer N or n, you should allow them to enter a new value and repeat the process. You will also need to reset the step counter variable to 0 for each new sequence

Has to look like this

image text in transcribed

C Collatz Conjecture Sequencer Enter an initial value for n(21000):1 Error: Invalid Value. Enter an value for n(21000):1500 Error: Invalid Value. Enter an value for n(21000):5 16 8 4 2 1 The end point of the sequence was found after 5 steps. Would you like to calculate the sequence for a difference value of n(Y/N):Y Enter an initial value for n(21000):7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

Comment on the pH value of lattice solutions of salts.

Answered: 1 week ago

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

3. You can gain power by making others feel important.

Answered: 1 week ago