Advertisement
dim4o

Loops_08_CatalanNumbersWithLong

Mar 26th, 2014
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             long num = long.Parse(Console.ReadLine());
  4.             if (num > 0 && num < 31)
  5.             {
  6.                 long numerator = 1;
  7.                 long denominator = 1;
  8.                 long result = 1;
  9.  
  10.                 for (int k = 2; k <= num; k++)
  11.                 {
  12.                     numerator *= (num + k);
  13.                     if (numerator % k == 0)
  14.                     {
  15.                         numerator /= k;
  16.                     }
  17.                     else
  18.                     {
  19.                         denominator *= k;
  20.                     }
  21.                 }
  22.                 result = numerator / denominator;
  23.                 Console.WriteLine(result);
  24.             }
  25.             else
  26.             {
  27.                 Console.WriteLine("out of range");
  28.             }        
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement