Example #1
0
        private static BigInteger Stirling_Calculate(BigInteger n, BigInteger k)
        {
            //(-1)^i(kCi)(k-i)^n = sum/k!
            BigInteger constant = -1;
            BigInteger i;
            BigInteger sum = 0;

            for (i = 0; i < k; i++)
            {
                //Console.WriteLine(PnC.PowerCalculator(constant, i) * PnC.nCr(k, i) * PnC.PowerCalculator(k-i, n));
                sum = sum + (PnC.PowerCalculator(constant, i) * PnC.nCr(k, i) * PnC.PowerCalculator(k - i, n));
            }
            //sum/k factorial
            return(sum / PnC.Factorial(k));
        }
        public void StirlingNumber()                                                                                                                    //STIRLING
        {
            base.Stirlingsign();
            BigInteger n;

stirling_n:
            Console.Write("Enter n: ", Color.White);
            String inp  = Console.ReadLine();
            bool   cont = true;

            while (cont)
            {
                if (inp.Trim() == "" || inp == " ")
                {
                    Console.Clear();
                    base.Stirlingsign();
                    Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White);
                    goto stirling_n;
                }
                else if (reg.Match(inp).Success)
                {
                    Console.Clear();
                    base.Stirlingsign();
                    Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White);
                    goto stirling_n;
                }
                else
                {
                    n = BigInteger.Parse(inp);
                    if (n <= 500 && n > 0)
                    {
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        base.Stirlingsign();
                        Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White);
                        goto stirling_n;
                    }
                }
            }
            Console.Clear();
            base.Stirlingsign();
            n = BigInteger.Parse(inp);
            BigInteger k;

            Console.WriteLine("Value of n: " + n, Color.White);
stirling_k:
            Console.Write("Enter r: ", Color.White);
            String inp2 = Console.ReadLine();

            while (cont)
            {
                if (inp2.Trim() == "" || inp2 == " ")
                {
                    Console.Clear();
                    base.Stirlingsign();
                    Console.WriteLine("Value of n: " + n, Color.White);
                    Console.WriteLine("Value of 'k' should be greater than 0, less than 500 and 'n' should be greater or equal to 'k'", Color.White);
                    goto stirling_k;
                }
                else if (reg.Match(inp2).Success)
                {
                    Console.Clear();
                    base.Stirlingsign();
                    Console.WriteLine("Value of n: " + n, Color.White);
                    Console.WriteLine("Value of 'k' should be greater than 0, less than 500 and 'n' should be greater or equal to 'k'", Color.White);
                    goto stirling_k;
                }
                else
                {
                    k = BigInteger.Parse(inp2);
                    if (k <= 500 && k > 0 && n >= k)
                    {
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        base.Stirlingsign();
                        Console.WriteLine("Value of n: " + n, Color.White);
                        Console.WriteLine("Value of 'k' should be greater than 0, less than 500 and 'n' should be greater or equal to 'k'", Color.White);
                        goto stirling_k;
                    }
                }
            }
            k = BigInteger.Parse(inp2);
            Console.Clear();
            base.Stirlingsign();
            Console.WriteLine("Value of n: " + n, Color.White);
            Console.WriteLine("Value of k: " + k, Color.White);
            Console.Write("S({0},{1}) is: ", n, k, Color.White);
            Console.Write(String.Format("{0:#,##0}", PnC.Stirling_method(n, k)), Color.IndianRed);
            Console.WriteLine();
            Choice();
        }
        public void Combination()                                                                                                                      //COMBI
        {
            base.Combinationsign();
            BigInteger n;

combi_n:
            Console.Write("Enter n: ", Color.White);
            String inp  = Console.ReadLine();
            bool   cont = true;

            while (cont)
            {
                if (inp.Trim() == "" || inp == " ")
                {
                    Console.Clear();
                    base.Combinationsign();
                    Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White);
                    goto combi_n;
                }
                else if (reg.Match(inp).Success)
                {
                    Console.Clear();
                    base.Combinationsign();
                    Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White);
                    goto combi_n;
                }
                else
                {
                    n = BigInteger.Parse(inp);
                    if (n <= 500 && n > 0)
                    {
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        base.Combinationsign();
                        Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White);
                        goto combi_n;
                    }
                }
            }
            Console.Clear();
            base.Combinationsign();
            n = BigInteger.Parse(inp);
            BigInteger r;

            Console.WriteLine("Value of n: " + n, Color.White);
combi_r:
            Console.Write("Enter r: ", Color.White);
            String inp2 = Console.ReadLine();

            while (cont)
            {
                if (inp2.Trim() == "" || inp == " ")
                {
                    Console.Clear();
                    base.Combinationsign();
                    Console.WriteLine("Value of n: " + n, Color.White);
                    Console.WriteLine("Value of 'r' should be less than 500 and 'n' should be greater or equal to 'r'", Color.White);
                    goto combi_r;
                }
                else if (reg.Match(inp2).Success)
                {
                    Console.Clear();
                    base.Combinationsign();
                    Console.WriteLine("Value of n: " + n, Color.White);
                    Console.WriteLine("Value of 'r' should be less than 500 and 'n' should be greater or equal to 'r'", Color.White);
                    goto combi_r;
                }
                else
                {
                    r = BigInteger.Parse(inp2);
                    if (r <= 500 && n >= r)
                    {
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        base.Combinationsign();
                        Console.WriteLine("Value of n: " + n, Color.White);
                        Console.WriteLine("Value of 'r' should be less than 500 and 'n' should be greater or equal to 'r'", Color.White);
                        goto combi_r;
                    }
                }
            }
            r = BigInteger.Parse(inp2);
            Console.Clear();
            base.Combinationsign();
            Console.WriteLine("Value of n: " + n, Color.White);
            Console.WriteLine("Value of r: " + r, Color.White);
            Console.Write("Combination of " + n + " and " + r + " with repetition is: ", Color.White);
            Console.Write(String.Format("{0:#,##0}", PnC.nCrWR(n, r)), Color.IndianRed);
            Console.WriteLine();
            Choice();
        }