Created
October 20, 2020 04:15
-
-
Save OldBigBuddha/112ee69bbdf3d3995064e1dd8cdf8656 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int collatz(int n) { | |
| if (n == 1) { | |
| cout << endl; | |
| return n; | |
| } | |
| int buf = n; | |
| if (n%2 == 0) { | |
| buf = buf / 2; | |
| } else { | |
| buf = n*3 + 1; | |
| } | |
| cout << " => " << buf; | |
| return collatz(buf); | |
| } | |
| int main() { | |
| int n; | |
| cout << "Number: "; | |
| cin >> n; | |
| cout << n; | |
| collatz(n); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment