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 CombinationX() //COMBIX { base.CombinationXsign(); BigInteger n; combiX_n: Console.Write("Enter n: ", Color.White); String inp = Console.ReadLine(); bool cont = true; while (cont) { if (inp.Trim() == "" || inp == " ") { Console.Clear(); base.CombinationXsign(); Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White); goto combiX_n; } else if (reg.Match(inp).Success) { Console.Clear(); base.CombinationXsign(); Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White); goto combiX_n; } else { n = BigInteger.Parse(inp); if (n <= 500 && n > 0) { break; } else { Console.Clear(); base.CombinationXsign(); Console.WriteLine("Value of 'n' should be greater than 0 and less than 500", Color.White); goto combiX_n; } } } Console.Clear(); base.CombinationXsign(); n = BigInteger.Parse(inp); BigInteger r; Console.WriteLine("Value of n: " + n, Color.White); combiX_r: Console.Write("Enter r: ", Color.White); String inp2 = Console.ReadLine(); while (cont) { if (inp2.Trim() == "" || inp2 == " ") { Console.Clear(); base.CombinationXsign(); 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 combiX_r; } else if (reg.Match(inp2).Success) { Console.Clear(); base.CombinationXsign(); 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 combiX_r; } else { r = BigInteger.Parse(inp2); if (r <= 500 && n >= r) { break; } else { Console.Clear(); base.CombinationXsign(); 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 combiX_r; } } } r = BigInteger.Parse(inp2); Console.Clear(); base.CombinationXsign(); Console.WriteLine("Value of n: " + n, Color.White); Console.WriteLine("Value of r: " + r, Color.White); Console.Write("Combination of " + n + " and " + r + " without repetition is: ", Color.White); Console.Write(String.Format("{0:#,##0}", PnC.nCr(n, r)), Color.IndianRed); Console.WriteLine(); Choice(); }