Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const string CommandExit = "exit";
- const string CommandSum = "sum";
- string inputMessage;
- int numberIput;
- int[] arrayNumbers = new int[0];
- bool isWorking = true;
- while (isWorking)
- {
- Console.Clear();
- Console.Write("Массив: ");
- for (int i = 0; i < arrayNumbers.Length; i++)
- {
- Console.Write(arrayNumbers[i] + " ");
- }
- Console.WriteLine($"\nСписок комманд:\n1--->{CommandSum}\n2--->{CommandExit}");
- Console.Write("Введите число или команду: ");
- inputMessage = Console.ReadLine();
- switch (inputMessage.ToLower())
- {
- case CommandSum:
- int arraySumNumbers = 0;
- for (int i = 0; i < arrayNumbers.Length; i++)
- {
- arraySumNumbers += arrayNumbers[i];
- }
- Console.WriteLine($"Сумма массива: {arraySumNumbers} ");
- arraySumNumbers = 0;
- Console.Write("Нажмите 'enter' для продолжения");
- Console.ReadKey();
- break;
- case CommandExit:
- Console.WriteLine("До свидания!");
- isWorking = false;
- break;
- default:
- numberIput = Convert.ToInt32(inputMessage);
- int[] tempArrayNumbers = new int[arrayNumbers.Length + 1];
- for (int i = 0; i < arrayNumbers.Length; i++)
- {
- tempArrayNumbers[i] = arrayNumbers[i];
- }
- tempArrayNumbers[tempArrayNumbers.Length - 1] = numberIput;
- arrayNumbers = tempArrayNumbers;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement