Advertisement
Jayss8

WCIPEG 3n+1 (C++)

Jun 19th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, i = 0;
  8.     cin >> n;
  9.    
  10.     while (n != 1)
  11.     {
  12.         i ++;
  13.         if ((n % 2) != 0)
  14.         {
  15.             n = n * 3 + 1;
  16.             continue;
  17.         }
  18.         else
  19.         {
  20.             n = n / 2;
  21.             continue;
  22.         }
  23.     }
  24.     cout << i;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement