Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Numerics;
- class DivideNFactorialByKFactorial
- {
- static void Main()
- {
- BigInteger numberN, numberK;
- string invalidInput = "Please enter a valid number! (1 < K < N)" + Environment.NewLine;
- while (true)
- {
- Stopwatch stopWatch = new Stopwatch();
- Console.WriteLine("Enter a value for N: ");
- while (!(BigInteger.TryParse(Console.ReadLine(), out numberN) && numberN > 1))
- {
- Console.WriteLine(invalidInput);
- Console.WriteLine("Enter a value for N: ");
- }
- Console.WriteLine("Enter a value for K: ");
- while (!(BigInteger.TryParse(Console.ReadLine(), out numberK) && numberK > 1 && numberK < numberN))
- {
- Console.WriteLine(invalidInput);
- Console.WriteLine("Enter a value for K: ");
- }
- BigInteger factorialDivision = 1;
- for (BigInteger i = numberK + 1; i <= numberN; i++)
- {
- stopWatch.Start();
- factorialDivision = factorialDivision * i;
- }
- Console.WriteLine("{0}! / {1}! = {2}" + Environment.NewLine, numberN, numberK, factorialDivision);
- stopWatch.Stop();
- TimeSpan ts = stopWatch.Elapsed;
- string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
- Console.WriteLine("runtime: " + elapsedTime + Environment.NewLine);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment