ellapt

6.9.10.Catalan

Dec 5th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class Catalan
  5. {
  6. static void Main()
  7. {
  8. string strNum;
  9. int n;
  10. int twoN;
  11. int i;
  12. do
  13. {
  14. Console.Write("Please, enter an unsigned integer number n: ");
  15. }
  16. while ((!int.TryParse(strNum = Console.ReadLine(), out n)) || n <= 0);
  17.  
  18. BigInteger nFactorial = 1;
  19. for (i = 1; i <= n; i++)
  20. {
  21. nFactorial *= i;
  22. }
  23.  
  24. BigInteger dividend = 1;
  25. twoN = 2 * n;
  26.  
  27. for (i = n + 2; i <= twoN; i++)
  28. {
  29. dividend *= i;
  30. }
  31. decimal catalan = (decimal)dividend/(decimal)nFactorial;
  32.  
  33. Console.WriteLine("The {0}-th Catalan number is: {1}", n,catalan);
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment