Advertisement
DARIMI27

Catalan numbers

Oct 30th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2. class CatalanNumbers
  3. {
  4.     static void Main()
  5.     {
  6.         Console.Write("Enter n (1<n<100) : ");
  7.         decimal n = decimal.Parse(Console.ReadLine());
  8.         decimal cn =1;
  9.         if (n==0)
  10.         {
  11.             Console.WriteLine("1");
  12.         }
  13.         else if (1<n&&n<100)
  14.         {
  15.             for (int k = 2; k <= n; k++)
  16.             {
  17.                 cn*=(n/k+1);
  18.                
  19.             }
  20.             Console.WriteLine("Cn = {0:F0}", cn);
  21.         }
  22.         else
  23.         {
  24.             Console.WriteLine("Invalid input!");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement