Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 7. Calculate N! / (K! * (N-K)!)
- //In combinatorics, the number of ways to choose k different members out of a group of n different elements (also known as the number of combinations) is calculated by the following formula:
- //For example, there are 2598960 ways to withdraw 5 cards out of a standard deck of 52 cards. Your task is to write a program that calculates n! / (k! * (n-k)!) for given n and k (1 < k < n < 100). Try to use only two loops.
- using System;
- using System.Numerics;
- class CalculateCombinatoric
- {
- static BigInteger FactorialCalc(uint number)
- {
- BigInteger sum = 1;
- for (int i = 1; i <= number; i++)
- {
- sum = sum * i;
- }
- return sum;
- }
- static void Main()
- {
- Console.WriteLine("Calculate N!/(K!*(N-K)!");
- Console.Write("Enter N:");
- uint n = uint.Parse(Console.ReadLine());
- Console.Write("Enter K:");
- uint k = uint.Parse(Console.ReadLine());
- BigInteger result = FactorialCalc(n) / ((FactorialCalc(k) * FactorialCalc(n - k)));
- Console.Write("The Result is:{0}",result);
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement