-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (34 loc) · 1.5 KB
/
Program.cs
File metadata and controls
41 lines (34 loc) · 1.5 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
// ЗАДАЧА:
//Написать программу, которая из имеющегося массива строк формирует массив из строк, длина которых либо меньше либо равна 3 символа. Первоначальный массив можно ввести с клавиатуры,
//либо задать на старте выполнения алгоритма. При решение не рекомендуется пользоваться коллекциями, лучше обойтись исключительно массивами.
int leng = 3;
int position = 0;
int size;
Console.Write($"Введите колличество элементов ");
int.TryParse(Console.ReadLine()!, out size);
string[] arrayStrings = new string[size];
for (int i = 0; i < size; i++)
{
System.Console.Write($"Введите {i+1}-й элемент: ");
string element = System.Convert.ToString(System.Console.ReadLine()!);
arrayStrings[i] = element;
}
string[] arrayElements = new string[size];
for (int e = 0; e < size; e++)
{
if (arrayStrings[e].Length <= leng)
{
arrayElements[position] = arrayStrings[e];
position++;
}
}
Console.WriteLine();
PrintArray(arrayElements);
void PrintArray(string[] array)
{
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine($"Элементы соответствующие требованиям массива[{array[i]}]");
}
Console.WriteLine();
}