Exemplo n.º 1
0
        private static int GeneralGCD(out TimeSpan executionTime, GCDDelegate gcd, int a, int b)
        {
            if (a == b && b == 0)
                throw new ArgumentOutOfRangeException("There are must be at least one non-zero number");

            var timer = Stopwatch.StartNew();

            int result = GCD(a, b);

            timer.Stop();
            executionTime = timer.Elapsed;

            return System.Math.Abs(result);
        }
Exemplo n.º 2
0
        private static int GeneralGCD(out TimeSpan executionTime, GCDDelegate gcd, params int[] numbers)
        {
            if (arrayHasOnlyZeros(numbers))
                throw new ArgumentOutOfRangeException("There are must be at least one non-zero number");

            var timer = Stopwatch.StartNew();

            int num = gcd(numbers[0], numbers[1]);

            for (int i = 2; i < numbers.Length; i++)
            {
                num = gcd(num, numbers[i]);
            }

            timer.Stop();
            executionTime = timer.Elapsed;

            return System.Math.Abs(num);
        }