Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Linq;
- using System.Numerics;
- using System.Threading.Tasks;
- namespace AsyncFactorial
- {
- class Program
- {
- static void Main(string[] args)
- {
- while (true)
- {
- Console.WriteLine("Введите целое число:");
- int outNumber;
- if(int.TryParse(Console.ReadLine(), out outNumber))
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- Task<BigInteger> taskFact = new Task<BigInteger>(()=>FactEven(outNumber));
- taskFact.Start();
- Task<BigInteger> taskFact1 = new Task<BigInteger>(() => FactUnEven(outNumber));
- taskFact1.Start();
- BigInteger x = taskFact.Result * taskFact1.Result;
- sw.Stop();
- TimeSpan timeSpan = sw.Elapsed;
- Console.WriteLine(timeSpan.ToString());
- Console.WriteLine(Environment.NewLine);
- }
- else
- {
- Console.WriteLine("Неверный вод числа");
- continue;
- }
- }
- }
- static BigInteger FactEven(int numberFactorial)
- {
- BigInteger resultFact = 2;
- for(int i = 4; i <= numberFactorial; i += 2)
- {
- resultFact *= i;
- }
- return resultFact;
- }
- static BigInteger FactUnEven(int numberFactorial)
- {
- BigInteger resultFact = 1;
- for (int i = 3; i <= numberFactorial; i += 2)
- {
- resultFact *= i;
- }
- return resultFact;
- }
- }
- }
Add Comment
Please, Sign In to add comment