Starting with any positive integer N, Collatz sequence is defined corresponding to n as the numbers formed by the following operations :
- If n is even, then n = n / 2.
- If n is odd, then n = 3*n + 1.
- Repeat above steps, until it becomes 1.
Input : 3 Output : 3, 10, 5, 16, 8, 4, 2, 1 Input : 6 Output : 6, 3, 10, 5, 16, 8, 4, 2, 1
Below is the implementation :
6 3 10 5 16 8 4 2 1
- G-Fact 21 | Collatz Sequence
- Maximum Sequence Length | Collatz Conjecture
- Program to implement Collatz Conjecture
- Print N terms of Withoff Sequence
- Print first N terms of Lower Wythoff sequence
- Print n terms of Newman-Conway Sequence
- Program to find sum of the given sequence
- Program to print the sum of the given nth term
- Program to print the Sum of series -1 + 2 + 11 + 26 + 47 +.....
- C Program to print Floyd's triangle
- Program to print first n Fibonacci Numbers | Set 1
- Program to print Fibonacci Triangle
- Program to print the series 2, 1, 4, 3, 6, 5, .... up to N terms
- Program to print GP (Geometric Progression)
- Program to print numeric pattern | Set - 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.