Question: Need help with 4-7 in my C++ program The entire hailstone sequence starting at n , all on one line, with the numbers separated by

Need help with 4-7 in my C++ program

  1. The entire hailstone sequence starting at n, all on one line, with the numbers separated by spaces.

  2. The length of the hailstone sequence that starts with n.

  3. The largest number in the hailstone sequence that starts with n.

  4. A longest hailstone sequence that starts with a number from 1 to n. (There might be two or more equally long sequences. Only one of those should be shown.)

  5. The length of the hailstone sequence shown in part 4.

  6. A hailstone sequence that starts with a number from 1 to n that contains the largest number.

  7. The largest number in the hailstone sequence shown in part 6.

________________________________________________________________________

What number shall I start with? 16 sequence: 16 8 4 2 1 length: 5 largest: 16 For start values from 1 to 16: longest: 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 length: 20 containing largest: 15 46 23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1 largest: 160

_________________________________________________________________________

What I have some far

_______________________________________________________

#include using namespace std;

// Creates the next input in a sequence int next(int n) { int x = n;

if (x % 2 == 0) { x = x / 2; return x; } else { x = 3 * x + 1; return x; } }

// Prints the whole sequence for your input void PrintSequence(int n) { for(int x = n; x > 1; x = next(x)) { printf("%i ", x); } printf("1"); }

int length(int n) { int count = 1; int x = n;

while(x > 1) { x = next(x); count++; } return count; } // Creates the largest number in the first sequence int largest(int n) { int max = n; int x = n;

while(x != 1) { if(max

int longestStart(int n) { }

int largestStart(int n) { }

int main() { int n = 0; printf("What number shall I start with? "); scanf("%i",&n); printf("sequence: "); PrintSequence(n); printf(" length: %i",length(n)); printf(" largest: %i",largest(n)); printf(" For start values from 1 to %i: ",n); printf(" longest: "); printf("length: "); printf(" containing largest: "); printf("largest: ");

return 0; }

_________________________________________________________

Need help with 4-7 in my C++ program The entire hailstone sequence

16 What number shall I start with? sequence: 16 8 4 2 1 length: 5 largest: 16 For start values from 1 to 16: longest: length: containing largest: largest

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!