kwest87

Untitled

Mar 31st, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 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 tempSum = 0;
  18.             int[] tempBag;
  19.             bool open = (true);
  20.  
  21.             while (open == true)
  22.             {
  23.                 Console.WriteLine("Введите команду :");
  24.                 command = Console.ReadLine();
  25.                 tempBag = new int[bag.Length + 1];
  26.  
  27.                 switch (command)
  28.                 {
  29.                     case "exit":
  30.                         open = false;
  31.                         break;
  32.                     case "sum":
  33.  
  34.                         for(int i = 1; i < bag.Length; i++)
  35.                         {
  36.                             sum+=bag[i];
  37.                         }
  38.                         Console.WriteLine(sum);
  39.                         sum = tempSum;
  40.                         break;
  41.                     default:
  42.  
  43.                         for (int i = 0; i < bag.Length; i++)
  44.                         {
  45.                             tempBag[i] = bag[i];
  46.                         }
  47.                         tempBag[tempBag.Length - 1] = Convert.ToByte(command);
  48.                         bag = tempBag;
  49.                         continue;
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
  55. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment