Example #1
0
        public void SolveTask()
        {
            Random random = new Random();

            int negativeSum = 0, min = int.MaxValue, max = int.MinValue;
            int startPos       = -1;
            int endPos         = -1;
            int multiplyResult = 1;

            Console.WriteLine("Array size:");

            int size = ConsoleReader.ReadInt();

            int[] array = new int[size];

            for (int i = 0; i < size; i++)
            {
                array[i] = random.Next(-100, 101);
                if (array[i] < 0)
                {
                    negativeSum += array[i];
                }

                if (array[i] < min)
                {
                    min      = array[i];
                    startPos = i;
                }

                if (array[i] > max)
                {
                    max    = array[i];
                    endPos = i;
                }

                Console.WriteLine(array[i]);
            }

            if (startPos > endPos)
            {
                Extentions.Swap(ref startPos, ref endPos);
            }

            for (int i = startPos + 1; i < endPos; i++)
            {
                multiplyResult *= array[i];
            }

            Console.WriteLine($"Negtive sum = {negativeSum}\nMultiply result = {multiplyResult}");
            Console.ReadKey();
        }
Example #2
0
        private static void Menu()
        {
            Console.Clear();
            Console.WriteLine("1\n2\n3\n4\nExit 0\n");

            Extentions.SafeRunning(Menu, $"Index out of bound, should be between 0 and {tasks.Length}");

            void Menu()
            {
                int task = ConsoleReader.ReadInt(0, tasks.Length, "Out of range");

                tasks[task].SolveTask();
            }
        }