-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask41
More file actions
40 lines (37 loc) · 1.17 KB
/
Task41
File metadata and controls
40 lines (37 loc) · 1.17 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: Пользователь вводит с клавиатуры M чисел.
// Посчитайте, сколько чисел больше 0 ввёл пользователь.
// 0, 7, 8, -2, -2 -> 2
// 1, -7, 567, 89, 223-> 3
Console.WriteLine("Введите размер массива");
int size = int.Parse(Console.ReadLine());
int num = 0;
int[] array = new int[size];
int count = 0;
int[] InPutArray(int[] array, int size, int num)
{
for (int i = 0; i < array.Length; i++)
{
if (num < size)
{
Console.WriteLine($"Введите {num+1} элемент массива");
array[num] = int.Parse(Console.ReadLine());
num++;
}
}
return array;
}
int CompareArrayNumbers(int[] array)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i] > 0) count++;
}
return count;
}
Console.WriteLine();
InPutArray(array, size, num);
CompareArrayNumbers(array);
Console.WriteLine();
Console.WriteLine("Получился следующий массив: ");
Console.WriteLine("[{0}]", string.Join(", ", array));
Console.WriteLine($"Элементов больше 0 в нём {count}");