Advertisement
Guest User

Catalan Numbers

a guest
Aug 24th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int n = int.Parse(Console.ReadLine());
  9.         if (n < 1)
  10.         {
  11.             Console.WriteLine("Invalid input,Please input N bigger or equal to 1!");
  12.         }
  13.         else
  14.         {
  15.             BigInteger factoriel = 1;
  16.             int temp = n+1;
  17.             int temp2 = n;
  18.             for (int i = 2*n; i > 1; i--)
  19.             {
  20.                 factoriel *= i;
  21.                 if (temp==i)
  22.                 {
  23.                     factoriel /= temp;
  24.                     temp--;
  25.                 }
  26.                 if (temp2 == i)
  27.                 {
  28.                     factoriel /= temp2;
  29.                     temp2--;
  30.                 }
  31.             }
  32.             Console.WriteLine(factoriel);
  33.         }
  34.            
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement