0

Hailstone Sequence so far

Good afternoon everyone, I'm currently working towards to provide the following output for my code: What number shall i start with? 7 The hailstone sequence starting at 7 is: 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 The length of the sequence is 17. The longest hailstone sequence starting with a number up to 7 has length 17 The longest hailstone sequence starting with a number up to 7 begins with 7 Below is what I've completed thus far: #include <iostream> #include <cstdio> #include <vector> using namespace std; //Function Variable Declaration. int lengthof_Sequence(int x), max_Sequence (int m), hailstone_Sequence (int n), count, length; int main(int argc, char** argv) { int user_Input, max_Input; cout << "What number shall I start with? "; cin >> user_Input; cout << user_Input << endl; cout << "\nThe lenght of the sequence is " << hailstone_Sequence (user_Input) << "."; cout << "\nThe largest number in the sequence is: \n"; cout << "The longest hailstone sequence starting " << user_Input << " with a number up to has length " << count<< "." <<endl; cout << "The longest hailstone sequence starting with a number up to " << user_Input << " begins with " << user_Input; return 0; } /* The hailstone sequence takes 'n' that is greater than 1 from the user. If // 'n' is even, computes n/2. If n is odd, computes 3n+1. Both are done till n = 1 // is reached. */ int hailstone_Sequence (int n) { int count = 1, lenth = 0; if (n > 1) { cout << "The hailstone of sequence starting at " << n << " is: " << endl; cout << n << " "; while (n > 1) { if ((n % 2) == 0 ) { n = n / 2; } else { n = 3 * n + 1; } cout << n <<

25th Jan 2017, 7:06 PM
Progress101
Progress101 - avatar
1 Respuesta
0
That's way too much for my nine year old brain!
24th Apr 2017, 12:08 AM
Brian