Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Store
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> array = new List<int>();
- bool work = true;
- while(work)
- {
- Console.WriteLine("Доступные команды: \n\n" +
- "1. Создать новый массив чисел \n\n" +
- "2. Добавить числа к массиву \n\n" +
- "3. Отсортировать числа \n\n" +
- "4. Вывести сумму элементов массива \n\n" +
- "5. Вывести элементы массива \n\n" +
- "6. Выход\n");
- switch(Console.ReadLine())
- {
- case "1":
- array = new List<int>();
- FillArrayMode(array);
- break;
- case "2":
- FillArrayMode(array);
- break;
- case "3":
- array.Sort();
- break;
- case "4":
- int sum = 0;
- foreach (var number in array)
- {
- sum += number;
- }
- Console.WriteLine("Сумма всех чисел равна " + sum);
- Console.ReadKey();
- break;
- case "5":
- foreach (var number in array)
- {
- Console.Write(number + " ");
- }
- Console.ReadKey();
- break;
- case "6":
- work = false;
- break;
- }
- Console.Clear();
- }
- }
- static void FillArrayMode(List<int> array)
- {
- Console.Clear();
- Console.WriteLine("Вы в режиме заполения массива. Чтобы добавить число, введите его и нажмите enter. Чтобы выйти введите esc");
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "esc")
- {
- break;
- }
- if (Int32.TryParse(input, out int number))
- {
- array.Add(number);
- }
- else
- {
- Console.WriteLine("Введите число!!!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement