Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[1];
- bool isActive = true;
- int sum = 0;
- Console.WriteLine("Введите любое число\n" +
- "sum - вывод суммы всех введеных ранее чисел\n" +
- "exit - выход");
- string userInput;
- while (isActive)
- {
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "exit":
- isActive = false;
- break;
- case "sum":
- foreach (int element in array)
- {
- sum += element;
- }
- Console.WriteLine(sum);
- sum = 0;
- 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;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment