Предмет: Информатика, автор: turgunovmanas413

Дан массив размера N. Вывести второй положительный элемент массива и его номер. С#​

Ответы

Автор ответа: matutopcic
0

using System;

namespace turgunovmanas413

{

   class Program

   {

       static int[] array = new int[100];

       static int n;

       static bool deleted;

       static void Input()

       {

           int i;

           Console.WriteLine("Количество элементов массива?");

           n = Convert.ToInt32(Console.ReadLine());

           Random r = new Random();

           for (i = 0; i < n; i++)

               array[i] = r.Next(-100, 101);

       }

       static void Output()

       {

           int i;

           for (i = 0; i < n; i++) Console.Write("{0,4}", array[i]);

               Console.WriteLine(); Console.WriteLine();

       }

       static void Del(int k)

       {

           for (int i = k; i < n - 1; i++)

           {

               array[i] = array[i + 1];

           }

           array[n] = 0;

           n = n - 1;

           deleted = true;

       }

       static void Solution()

       {

           int j = 0;

           for (int i = 0; i < array.Length; i++)

           {

               if (array[i] % 2 == 0)

                   j++;

               if (j == 2)

               {

                   Del(i);

                   break;

               }

           }

           if (!deleted)

               Console.WriteLine(" Элемент не найден");

       }

       static void Main()

       {

           deleted = false;

           Input();

           Output();

           Solution();

           Output();

           Console.ReadKey();

       }

   }

}


turgunovmanas413: здесь правильно?
turgunovmanas413: там не правильно
turgunovmanas413: оказывается
matutopcic: где неправельно?
matutopcic: Строчку
matutopcic: У меня всё включаеться и роботает бро
turgunovmanas413: там нумерация массива не выходит
Похожие вопросы