Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StartCode]
- using System;
- namespace ConsoleApp14
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string commandSum = "sum";
- const string commandExit = "exit";
- string userInput;
- int[] array = new int[0];
- bool isWork = true;
- while (isWork)
- {
- Console.WriteLine($"Введите команду : цифру , {commandSum} или {commandExit}.");
- userInput = Console.ReadLine();
- if (userInput == commandSum)
- {
- int sumNumber = 0;
- for (int i = 0; i < array.Length; i++)
- {
- sumNumber += array[i];
- }
- Console.WriteLine(sumNumber);
- }
- else if (userInput == commandExit)
- {
- isWork = false;
- }
- else
- {
- int[] temporaryArray = new int[array.Length + 1];
- temporaryArray[array.Length] = Convert.ToInt32(userInput);
- for (int i = 0; i < array.Length; i++)
- {
- temporaryArray[i] = array[i];
- }
- array = temporaryArray;
- }
- }
- }
- }
- }
- [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment