Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp27
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = new List<int>();
- string userInput;
- bool isWorking = true;
- int number;
- int positive;
- while (isWorking)
- {
- Console.Write("Введите число: ");
- userInput = Console.ReadLine();
- if (userInput == "0")
- {
- isWorking = false;
- break;
- }
- else
- {
- if (int.TryParse(userInput,out number))
- numbers.Add(number);
- else
- Console.WriteLine("Вводите только числа!");
- }
- }
- ShowCollection(numbers);
- PosNegSeq(numbers, out positive);
- Console.WriteLine($"Кол-во положительных: {positive}\n" +
- $"Кол-во отрицательных: {numbers.Count - positive}");
- }
- private static void ShowCollection<T>(List<T> collection)
- {
- foreach (T item in collection)
- Console.Write($"{item} ");
- }
- private static void PosNegSeq(List<int> numbers, out int positive)
- {
- positive = 0;
- foreach (int number in numbers)
- if (number > 0)
- positive += 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment