Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
РГЗ варианты 11 - 19.docx
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
51.34 Кб
Скачать

Вариант 16

Random rnd = new Random();

int n = rnd.Next(5, 12);

double[] a = new double[n];

int[] b = new int[n];

double[] arrayModify = new double[n];

//Вывод исходного массива на экран

Console.ForegroundColor = ConsoleColor.Green;

Console.WriteLine("Исходный массив:");

Console.ForegroundColor = ConsoleColor.Red;

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

{

Console.Write("{0,6}", i);

}

Console.WriteLine();

Console.ForegroundColor = ConsoleColor.White;

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

{

a[i] = -5 + 10 * rnd.NextDouble();

Console.Write("{0,6:f2}", a[i]);

}

Console.WriteLine();

Console.WriteLine();

double C = -2;

double f = 0;

Console.ForegroundColor = ConsoleColor.Green;

Console.Write("Kоличество элементов массива, меньших С (C = -2):");

Console.ForegroundColor = ConsoleColor.Red;

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

{

if (a[i] < C)

{

f = f + 1;

}

}

Console.WriteLine("{0,4}", f);

Console.ForegroundColor = ConsoleColor.Green;

//Найти последний отрицательный элемент

int ml = 0;

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

{

if (a[i] < 0)

{

if (ml < i)

ml = i;

}

}

Console.Write("Последний отрицательный элемент массива: ");

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("{0,4:f2}", a[ml]);

//Найти сумму целых частей элементов массива, расположенных после последнего отрицательного элемента

Console.ForegroundColor = ConsoleColor.Green;

int s = 0;

for (int i = ml+1; i < n; i++)

{

b[i] = (int) a[i];

s = s + b[i];

}

Console.Write("Сумма целых частей элементов, рас-ных после последнего отриц. элемента: ");

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("{0}", s);

Console.WriteLine();

//Преобразование массива

Console.ForegroundColor = ConsoleColor.Green;

int max = 0;

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

if (a[max] < a[i])

max = i;

Console.WriteLine("Преобразованный массив:");

int l = -1;

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

{

if ((a[i] <= 1.2 * a[max]) && (a[i] >= 0.8 * a[max]))

{

l++;

arrayModify[l] = a[i];

}

}

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

{

if ((a[i] > 1.2 * a[max]) || (a[i] < 0.8 * a[max]))

{

l++;

arrayModify[l] = a[i];

}

}

Console.ForegroundColor = ConsoleColor.Red;

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

{

Console.Write("{0,6}", i);

}

Console.WriteLine();

Console.ForegroundColor = ConsoleColor.White;

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

{

Console.Write("{0,6:f2}", arrayModify[i]);

}

Console.WriteLine();