Advertisement
Jayss8

WCIPEG 3n+1 (C#)

Jun 19th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace 3n_1CSharp
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int n, i = 0;
  10.  
  11.             n = Console.Read();
  12.  
  13.             while (n != 1)
  14.             {
  15.                 i ++;
  16.  
  17.                 if ((n % 2) != 0)
  18.                 {
  19.                     n = n * 3 + 1;
  20.                 }
  21.                 else
  22.                 {
  23.                     n = n / 2;
  24.                 }
  25.             }
  26.             Console.WriteLine(i);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement