Advertisement
Guest User

collatz

a guest
Mar 7th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int num;
  8.  
  9.     cout << "Enter a number: ";
  10.     cin >> num;
  11.     cout << "Collatz Conjecture : ";
  12.  
  13.     while (num != 1)
  14.     {
  15.         cout << num << " ";
  16.  
  17.         if (num % 2) num = 3*num + 1;
  18.         else num = num/2;
  19.     }
  20.  
  21.     cout << 1 << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement