Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var myClass     = new NumberAsArray();
            var myHelpClass = new HelperClass();

            Console.Write("Enter the length of first integer: ");
            int firstIntLenght = int.Parse(Console.ReadLine());

            Console.Write("Enter the length of second integer: ");
            int secondIntLenght = int.Parse(Console.ReadLine());

            int[] firstNumber  = myHelpClass.GenerateRandomArray <int>(firstIntLenght, 10);
            int[] secondNumber = myHelpClass.GenerateRandomArray <int>(secondIntLenght, 10);

            //// Hardcode values
            // firstNumber = new int[6] { 1, 2, 3, 4, 5, 6 };
            // secondNumber = new int[3] { 7, 8, 9 };

            int pad = 0;
            int lengthDifference = firstIntLenght - secondIntLenght;

            Console.WriteLine();
            Console.Write("First number:");
            pad = Console.CursorLeft + 4;
            if (lengthDifference < 0)
            {
                pad += Math.Abs(lengthDifference * 2);
            }

            Console.SetCursorPosition(pad, Console.CursorTop);
            myHelpClass.PrintArray(firstNumber);

            Console.WriteLine();
            Console.Write("Second number:");
            pad = Console.CursorLeft + 3;
            if (lengthDifference > 0)
            {
                pad += Math.Abs(lengthDifference * 2);
            }

            Console.SetCursorPosition(pad, Console.CursorTop);
            myHelpClass.PrintArray(secondNumber);
            Console.WriteLine();

            int[] resultNumber = myClass.SumBigIntegers(firstNumber, secondNumber);
            Console.Write("Result number:");
            pad = Console.CursorLeft + 3;
            Console.SetCursorPosition(pad, Console.CursorTop);
            myHelpClass.PrintArray(resultNumber);
            Console.WriteLine();
        }
Exemplo n.º 2
0
    private int[] ProductBigIntegers(int[] firstNumber, int[] secondNumber)
    {
        var mySumBigInt = new MySpace.NumberAsArray();

        int[] result = new int[1] {
            0
        };
        int numberLenght = firstNumber.Length;

        int[] counter           = new int[numberLenght];
        int   possitionInNumber = 0;

        counter[numberLenght - 1] = 1;

        while (true)
        {
            possitionInNumber = numberLenght - 1;
            while (counter[possitionInNumber] <= firstNumber[possitionInNumber])
            {
                result = mySumBigInt.SumBigIntegers(result, secondNumber);
                counter[possitionInNumber]++;
            }

            counter[possitionInNumber]++;

            while (counter[possitionInNumber] > firstNumber[possitionInNumber])
            {
                counter[possitionInNumber]     = 0;
                firstNumber[possitionInNumber] = 9;
                possitionInNumber--;

                if (possitionInNumber < 0)
                {
                    return(result);
                }

                counter[possitionInNumber] = counter[possitionInNumber] + 1;
            }
        }
    }