-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (56 loc) · 1.15 KB
/
Program.cs
File metadata and controls
64 lines (56 loc) · 1.15 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
55
56
57
58
59
60
61
62
63
64
Console.Write("Введите числа через запятую: ");
int[] numbers = String(Console.ReadLine());
PrintArray(numbers);
int sum = 0;
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] > 0)
{
sum++;
}
}
Console.WriteLine();
Console.WriteLine($"количество значений > 0 = {sum}");
int[] String(string input)
{
int count = 1;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == ',')
{
count++;
}
}
int[] numbers = new int [count];
int index = 0;
for (int i = 0; i < input.Length; i++)
{
string temp = "";
while (input [i] != ',')
{
if(i != input.Length - 1)
{
temp += input [i].ToString();
i++;
}
else
{
temp += input [i].ToString();
break;
}
}
numbers[index] = Convert.ToInt32(temp);
index++;
}
return numbers;
}
void PrintArray(int[] array)
{
Console.Write("");
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
}
Console.Write("");
}