Skip to content

Instantly share code, notes, and snippets.

@vdonchev
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdonchev/5b1eb89970f02ad16951 to your computer and use it in GitHub Desktop.
Save vdonchev/5b1eb89970f02ad16951 to your computer and use it in GitHub Desktop.
Console.Write("Enter number between 1 and 100 (n):");
int n = int.Parse(Console.ReadLine());
if (1 < n && n < 100)
{
BigInteger doubleN = 1;
BigInteger nPlus = 1;
BigInteger num = 1;
for (int i = 2; i <= n * 2; i++)
{
doubleN *= i;
if (i <= n + 1)
{
nPlus *= i;
}
if (i <= n)
{
num *= i;
}
}
BigInteger result = doubleN / (nPlus * num);
Console.WriteLine("Catalan(n) = " + result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment