#include using namespace std; int collatz(int N) { int count = 0; while (true) { cout << N << " "; count = count + 1; if (N == 1) break; if (N % 2 == 0) N = N / 2; else N = 3 * N + 1; } return count; } int main() { int N; cout << "Enter the starting value: "; cin >> N; if (N <= 0) { cout << "Only positive starting points are valid.\n"; exit(1); } const int length = collatz(N); cout << "\n"; cout << "The length of the sequence is " << length << "\n"; }