kwest87

Untitled

Mar 31st, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp1
  9. {
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int[] bag = new int[1];
  15.             string command;
  16.             int sum =0 ;
  17.             int[] tempBag = new int[bag.Length + 1];
  18.             bool open = (true);
  19.  
  20.             while (open == true)
  21.             {
  22.                 Console.WriteLine("Введите команду :");
  23.                 command = Console.ReadLine();
  24.                 tempBag = new int[bag.Length + 1];
  25.  
  26.                 switch (command)
  27.                 {
  28.                     case "exit":
  29.                         open = false;
  30.                         break;
  31.                     case "sum":
  32.                         Console.WriteLine(sum);
  33.                         break;
  34.                     default:
  35.                         for (int i = 0; i < bag.Length; i++)
  36.                         {
  37.                             tempBag[i] = bag[i];
  38.                         }
  39.                         tempBag[tempBag.Length - 1] = Convert.ToByte(command);
  40.                         bag = tempBag;
  41.                         sum += bag[bag.Length - 1];
  42.                         continue;
  43.                 }
  44.             }
  45.         }
  46.     }
  47. }
  48. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment