//file Prog001v0.cpp
//author AOU
#include <iostream>
using namespace std;
/*
input n1, n2
output the longest maxCycleLength
Algorithm0: to display all the numbers
get a value for n
display n
do while n > 1
if n is even then
n = n/2
else
n = 3*n + 1
end if
display n
end while
*/
void main (void)
{
int n;
cin >> n;
cout << n << ' ';
while (n > 1)
{
if (n%2 == 0)
n = n/2;
else
n = 3*n + 1;
cout << n << ' ';
}
cout << endl;
}
/*
22
22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
Press any key to continue
*/
|