using System; namespace ConsoleApplication1 { class Program { static int parse(string message) { Console.Write(message); string buf = ""; int y = 1, x = 1; Boolean check; ; do { try { check = true; buf = Console.ReadLine(); x = int.Parse(buf); if (x < 0) throw new ArithmeticException(); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.Beep(300, 600); Console.WriteLine("Введённые данные неверны, повторите попытку"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(message); check = false; y++; if (y > 5) { for (int t = 3; t > 0; --t) { Console.Clear(); Console.WriteLine("Программа закроется через {0} с. ", t); System.Threading.Thread.Sleep(1000); } Console.Clear(); Console.ForegroundColor = ConsoleColor.Gray; Environment.Exit(0); } } Console.ForegroundColor = ConsoleColor.Gray; } while (!check && y <= 5); return x; } // метод для ввода переменных вещественного типа static void Main(string[] args) { int n = parse("Введите количество элементов массива \nN = "); Random random = new Random(); double[] a = new double[n]; for (int i = 0; i < n; ++i) { double r1 = Math.Round(random.Next(0, 50) + random.NextDouble(),1); double r2 = Math.Round(random.Next(0, 50) + random.NextDouble(),1); a[i] = r1 -r2; } double min = a[0]; for (int i = 0; i < n; ++i) { if (a[i] < min) min = a[i]; } Console.WriteLine("Минимальный элемент массива: " + min); double inf = double.PositiveInfinity; double firstplus = inf; int lasti = 0, firsti = 0; for (int i = 0; i < n && firstplus == inf; ++i) { if (a[i] > 0) { firstplus = a[i]; firsti = i; } } double lastplus = inf; for (int i = n - 1; i >= 0 && lastplus == inf; --i) { if (a[i] > 0) { lasti = i; lastplus = a[i]; } } bool check = true; if (firstplus == inf) { Console.WriteLine("В массиве нет положительных элементов"); check = false; } else { if (firsti == lasti) { Console.WriteLine("В массиве только один положительный элемент"); check = false; } } if (firsti + 1 == lasti) { Console.WriteLine("Последнее положительное идет сразу за первым"); check = false; } if (check == true) { double summ = 0; int isumm; for (isumm = firsti + 1; isumm < lasti; ++isumm) { summ += a[isumm]; } Console.WriteLine("Сумма эл. массива между первым и последним положительным элементом равна " + summ); } int isort, isort2 = 0; for (isort = 0; isort < n; ++isort) { if (a[isort] == 0) { a[isort] = a[isort2]; a[isort2] = 0; isort2++; } } Console.WriteLine("Отсортированный массив:"); foreach (double element in a) { Console.Write(element + " "); } Console.WriteLine(); } } }