Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int[] array = new int[1];
- string userInput;
- bool isRunning = true;
- string summCommand = "sum";
- string exitCommand = "exit";
- while (isRunning == true)
- {
- Console.Write("Введите команду: ");
- userInput = Console.ReadLine();
- if (userInput == summCommand)
- {
- int summ = 0;
- foreach (var number in array)
- summ += number;
- Console.WriteLine(summ);
- }
- else if (userInput == exitCommand)
- {
- isRunning = false;
- }
- else
- {
- int userNumber;
- int[] tempArray;
- if (int.TryParse(userInput, out userNumber))
- {
- tempArray = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = userNumber;
- array = tempArray;
- Console.WriteLine("Введено число " + userNumber);
- }
- else
- {
- Console.WriteLine("Неверный ввод команды!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement