Advertisement
Martichka

Loops/Task 9/10 - Catalan numbers

Dec 10th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. class CatalanNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         int num = int.Parse(Console.ReadLine());
  8.         BigInteger factTwoN=1, factN=1, factNOne=1;
  9.         int doubleNum = 2*num;
  10.         int numPlusOne = num+1;
  11.         while (num > 0)
  12.         {
  13.             factN *= num;
  14.             num--;
  15.         }
  16.         while (doubleNum > 0)
  17.         {
  18.             factTwoN *= doubleNum;
  19.             doubleNum--;
  20.         }
  21.         while (numPlusOne > 0)
  22.         {
  23.             factNOne *= numPlusOne;
  24.             numPlusOne--;
  25.         }
  26.         Console.WriteLine(factTwoN/(factNOne*factN));
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement