Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp9
- {
- class Program
- {
- static void Main(string[] args)
- {
- int sum;
- bool isWork = true;
- string userInput;
- int[] array = new int[0];
- while (isWork)
- {
- Console.Clear();
- Console.WriteLine("Комманды:\nexit\nsum\nПишите цифры я их запомню, и сумирую если попросите)");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "exit":
- isWork = false;
- break;
- case "sum":
- sum = 0;
- for (int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- Console.Write($"{array[i]} ");
- }
- Console.WriteLine($"\nСумма введенных чисел: {sum}\nНажмите любую клавишу для продолжения...");
- Console.ReadKey();
- break;
- default:
- int[] tempArray = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = Convert.ToInt32(userInput);
- array = tempArray;
- break;
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement