Question
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 exactly like picture.
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
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