Exemple #1
0
        static void Main(string[] args)
        {
            int[,,] myThreeDimensionArrray = new int[sizeOneDimensionArray, sizeTwoDimensionArray, sizeThreeDimensionArray];
            Random random = new Random();

            Console.WriteLine("Исходный массив:");
            for (int i = 0; i < myThreeDimensionArrray.GetLength(0); i++)
            {
                for (int j = 0; j < myThreeDimensionArrray.GetLength(1); j++)
                {
                    Console.Write("[");
                    for (int k = 0; k < myThreeDimensionArrray.GetLength(2); k++)
                    {
                        myThreeDimensionArrray[i, j, k] = random.Next(minValueRandom, maxValueRandom);
                        MyArrayMethods.FormattingDisplay(myThreeDimensionArrray[i, j, k]);
                        if (k == (myThreeDimensionArrray.GetLength(2) - 1))
                        {
                            Console.Write($"{myThreeDimensionArrray[i, j, k]}");
                        }
                        else
                        {
                            Console.Write($"{myThreeDimensionArrray[i, j, k]}, ");
                        }
                        if (myThreeDimensionArrray[i, j, k] > 0)
                        {
                            myThreeDimensionArrray[i, j, k] = 0;
                        }
                    }
                    Console.Write("] ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Обработанный массив:");
            for (int i = 0; i < myThreeDimensionArrray.GetLength(0); i++)
            {
                for (int j = 0; j < myThreeDimensionArrray.GetLength(1); j++)
                {
                    Console.Write("[");
                    for (int k = 0; k < myThreeDimensionArrray.GetLength(2); k++)
                    {
                        MyArrayMethods.FormattingDisplay(myThreeDimensionArrray[i, j, k]);
                        if (k == (myThreeDimensionArrray.GetLength(2) - 1))
                        {
                            Console.Write($"{myThreeDimensionArrray[i, j, k]}");
                        }
                        else
                        {
                            Console.Write($"{myThreeDimensionArrray[i, j, k]}, ");
                        }
                    }
                    Console.Write("] ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            int[,] myTwoDimensionArray = new int[sizeOneDimensionArray, sizeTwoDimensionArray];
            int    sumEvenPositionElementsArray = 0;
            Random random = new Random();

            for (int i = 0; i < myTwoDimensionArray.GetLength(0); i++)
            {
                for (int j = 0; j < myTwoDimensionArray.GetLength(1); j++)
                {
                    myTwoDimensionArray[i, j] = random.Next(minValueRandom, maxValueRandom);
                    if ((i + j) % 2 == 0)
                    {
                        sumEvenPositionElementsArray += myTwoDimensionArray[i, j];
                    }
                    MyArrayMethods.FormattingDisplay(myTwoDimensionArray[i, j]);
                    Console.Write($"{myTwoDimensionArray[i, j]} ");
                }
                Console.WriteLine();
            }
            Console.WriteLine($"Сумма элементов массива, стоящих на четных позициях: {sumEvenPositionElementsArray}");

            Console.ReadKey();
        }