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 length 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, length = 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 << " ";
count++;
}
length = count;
}
return count;
}
/* Lengthof_Sequence
// returns *pending*
//
*/
int lengthof_Sequence(int x)
{
}
int max_Sequence (int m)
{
}
I'm having trouble coming up with a way to print the max and this line "The longest hailstone sequence starting 7 with a number up to has length____." for the output. Does anyone have any advice or suggestions?