Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StartCode]
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int[] bag = new int[1];
- string command;
- int sum =0;
- int tempSum = 0;
- int[] tempBag;
- bool open = (true);
- while (open == true)
- {
- Console.WriteLine("Введите команду :");
- command = Console.ReadLine();
- tempBag = new int[bag.Length + 1];
- switch (command)
- {
- case "exit":
- open = false;
- break;
- case "sum":
- for(int i = 1; i < bag.Length; i++)
- {
- sum+=bag[i];
- }
- Console.WriteLine(sum);
- sum = tempSum;
- break;
- default:
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = Convert.ToByte(command);
- bag = tempBag;
- continue;
- }
- }
- }
- }
- }
- [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment