// Program: collatz.cpp
// Compute the Collatz sequence of a number n.
#include
int main()
{
// Input
std::cout << "Compute the Collatz sequence for n =? ";
unsigned int n;
std::cin >> n;
// Iteration
while (n > 1) {
if (n % 2 == 0)
n = n / 2;
else
n = 3 * n + 1;
std::cout << n << " ";
}
std::cout << "\n";
return 0;
}