Page 1 of 1

Given a natural number n, generate a sequence of integers described in the Collatz conjecture: If n is even, divide it i

Posted: Wed Apr 27, 2022 3:43 pm
by answerhappygod
Given A Natural Number N Generate A Sequence Of Integers Described In The Collatz Conjecture If N Is Even Divide It I 1
Given A Natural Number N Generate A Sequence Of Integers Described In The Collatz Conjecture If N Is Even Divide It I 1 (65.57 KiB) Viewed 41 times
Given a natural number n, generate a sequence of integers described in the Collatz conjecture: If n is even, divide it in half. If it is odd, multiply it by 3 and add 1. Repeat this operation until reaching 1. For example, if n = 17, the sequence looks as follows: 17 52 26 13 40 20 10 5 16 8 421 The conjecture states that such a sequence will eventually reach 1 for any value of n. O Output format: Sequence of integers in a single line, separated by single spaces. For example: Input Result 18 18 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1