using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Control { internal class Class5 { int[] mass; public Class5(int n) { Random random = new Random(); mass = new int[n]; Console.Write("Массив: "); for (int i = 0; i < mass.Length; i++) { mass[i] = random.Next(-50, 51); Console.Write($"{mass[i]} "); } Console.WriteLine(); } public void modifiedArray() { int[] mass2 = new int[mass.Length]; int firstOtr = 0; int firstPol = 0; for (int i = 0; i < mass.Length; i++) { if (mass[i] < 0) { firstOtr = i; break; } } for (int i = 0; i < mass.Length; i++) { if (mass[i] > 0) { firstPol = i; break; } } for (int i = 0; i < mass.Length; i++) { if (i == firstOtr) { mass2[i] = mass[firstPol]; } else if (i == firstPol) { mass2[i] = mass[firstOtr]; } else { mass2[i] = mass[i]; } } Console.Write("Новый массив: "); foreach (int el in mass2) { Console.Write($"{el} "); } Console.WriteLine(); } } }