i'm trying to write a program that takes two numbers from the user prints out the sequence between the 2 numbers and then outputs wthe longest sequence
for example if the user inputed 8 and 10
it should out put
8 4 2 1
9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
10 5 16 8 4 2 1
i got the code as follows that does it for 1 number
#include <iostream>
using namespace std;
int f(int n);
int main()
{
int first;
cout << "Enter First Integer: ";
cin >> first;
while(first != 1) //test ithat first is not qual to 1
{
cout << first << " ";
first = f(first);//call function
}
cout << first << endl;
return 0;
}
int f(int n)
{
if(n %2 == 0)//test to see if even
{
return n /=2;
}
else
{
return n = 3*n+1;//is odd
}
}
i need it to do it for two numbers and out but the sequence between those two numbers and then compare them and output that number 9 is the longest sequence it contained 20 numbers any help with this would greatly be appreeciated. forgive me i'm new to the forum and i'm not sure how to use
the code tags.