collatz Algorithm

The sequence of numbers involved is sometimes referred to as the hailstone sequence or hailstone numbers (because the values are normally subject to multiple descents and ascents like hailstones in a cloud), or as wondrous numbers. It is also known as the 3n + 1 problem, the 3n + 1 conjecture, the Ulam conjecture (after Stanisław Ulam), Kakutani's problem (after Shizuo Kakutani), the Thwaites conjecture (after Sir Bryan Thwaites), Hasse's algorithm (after Helmut Hasse), or the Syracuse problem.
//
// Collatz sequenge algorithm implementation in C++
//
// The All ▲lgorithms Project
//
// https://allalgorithms.com/cpp/math/collatz-sequenge
// https://github.com/allalgorithms/cpp
//
// Contributed by: Pablo Trinidad
// Github: @pablotrinidad
//
#include <bits/stdc++.h>
using namespace std;

void collatz(int n) {
    while (n > 1) {
        cout << n << " ";
        if (n % 2 == 0) {
            n = n / 2;
        } else {
            n = (3 * n) + 1;
        }
    }
    cout << n << endl;
}
int main() {
    int n;
    cout << "Enter an integer n to compute the Collatz sequence: ";
    cin >> n;
    collatz(n);
    return 0;
}

LANGUAGE:

DARK MODE: