Question: Previous Week Lab: #include #include int main() { // Declaring variables int max = -999, count = 0; long k; while(1) { // Getting the

 Previous Week Lab: #include #include int main() { // Declaring variables

Previous Week Lab:

#include #include

int main() { // Declaring variables int max = -999, count = 0; long k; while(1) { // Getting the input entered by the user printf("Enter a starting number: "); scanf("%ld",&k); if(k

printf("Collatz sequence: "); printf("%ld, ",k); count++; // This while loop continues to execute until the n value becomes 1 while (k != 1) { // if n is even then this block of code will be executed if (k % 2 == 0) { count++; k = k / 2; } else { count++; // if n is odd then this block of code will be executed k = (3 * k + 1); } if (k != 1) { printf("%ld",k); if(k!=1) { printf(", "); } } } printf("%ld",k);

printf(" Length: %d ",count);

return 0; }

In this short assignment you will declare fill an integer array with values as described here: Elements 0-9 The values 0..9 Elements 10-19 The values 100, 110, 120, ..., 190 Elements 20-25 The values 4, 8, 15, 16, 23, 42 Elements 26-39 The first fourteen values in the Collatz sequence, starting with 7. Except for elements 20-25, you should loops and computed values to fill the array. That is, figure out a way to compute the values for the elements, perhaps by using the loop counter. For the Collatz numbers, utilize the function you wrote for the previous week's lab assignment. Before your program exists, finish with a loop to print out the contents of the array. What to Turn In A single C file, uploaded here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!