kwest87

Untitled

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