-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (38 loc) · 1.48 KB
/
Program.cs
File metadata and controls
44 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Задача: Написать программу, которая из имеющегося массива строк формирует новый массив из строк,
// длина которых меньше, либо равна 3 символам.
// Первоначальный массив можно ввести с клавиатуры, либо задать на старте выполнения алгоритма.
// При решении не рекомендуется пользоваться коллекциями, лучше обойтись исключительно массивами.
int size;
Console.Write("Введите количество элементов массива: ");
int.TryParse(Console.ReadLine()!, out size);
string[] array1 = new string[size];
for (int i = 0; i < size; i++)
{
Console.Write("Введите элемент массива: ");
string result = Console.ReadLine()!;
array1[i] = result;
}
Console.WriteLine();
Console.Write("Введенный массив: [");
Console.Write(string.Join(" ", array1));
Console.Write("]");
int n = 0;
for (int i = 0; i < array1.Length; i++)
{
if (array1[i].Length <= 3)
n++;
}
Console.WriteLine();
Console.Write("Новый массив: [");
string[] array2 = new string[n];
int j = 0;
for (int i = 0; i < array1.Length; i++)
{
if (array1[i].Length <= 3)
{
array2[j] = array1[i];
Console.Write(array2[j] + " ");
j++;
}
}
Console.Write("]");