-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (48 loc) · 1.51 KB
/
Copy pathProgram.cs
File metadata and controls
55 lines (48 loc) · 1.51 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
45
46
47
48
49
50
51
52
53
54
// Задайте массив заполненный случайными положительными трёхзначными числами. Напишите программу,
// которая покажет количество чётных чисел в массиве.
// [345, 897, 568, 234] -> 2
int ReadInt (string message)
{
System.Console.WriteLine($"{message} > ");
return int.Parse(Console.ReadLine());
}
int[] CreateArray( int length, int minRnd, int maxRnd)
{
int[] array = new int[length];
Random rnd = new Random();
for (int i = 0; i < length; i++)
{
array[i] = rnd.Next(minRnd, maxRnd+1);
}
return array;
}
int length = ReadInt("Введите длину массива ");
int minRnd = ReadInt("Введите границу минимума ");
int maxRnd = ReadInt("Введите границу максимума ");
int[] array = CreateArray(length, minRnd, maxRnd);
PrintArray(array);
void PrintArray(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
System.Console.Write($"{array[i]}\t");
}
}
int result = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] % 2 == 0)
{
result++;
}
}
if (result % 10 == 1)
{
Console.WriteLine($"В массиве {result} четное число");
}
if (result % 10 == 2 || result % 10 == 3 || result % 10 == 4)
{
Console.WriteLine($"В массиве {result} четных числа");
}
else
Console.WriteLine($"В массиве {result} четных чисел");