I have this problem... Ive gotten the codes however, i cant seems to get the output correctly..
This is my program:
int n;
cin>>n; //reading in value of n
if (n==1)
{
cout<<n; //if n=1, print out 1
}
else if (n%2)
{
n = 3*n + 1; //if n is an odd number, print out n = 3*n + 1
}
else
{
n = n/2; //or else print n = n/2
}
cout<<n; //printing the number n
The result that I have gotten when i type in 22 is 11, which is correct.. However, Im supposed to display this result
-> 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
I tried putting in a for loop -> for (int n=0;n<1000000;n++) but it doesnt work... I coulnt get any output at all when i add the for loop.. the problem states that integer n has value from 0<n<1000000.. what should i do to correct this problem.. So sorry, Im new in this..