Advertisement
Suslick

Task_4

Jan 30th, 2023 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             int[] array = new int[1];
  4.             string userInput;
  5.             bool isRunning = true;
  6.             string summCommand = "sum";
  7.             string exitCommand = "exit";
  8.  
  9.             while (isRunning == true)
  10.             {
  11.                 Console.Write("Введите команду: ");
  12.                 userInput = Console.ReadLine();
  13.  
  14.                 if (userInput == summCommand)
  15.                 {
  16.                     int summ = 0;
  17.  
  18.                     foreach (var number in array)
  19.                         summ += number;
  20.  
  21.                     Console.WriteLine(summ);
  22.                 }
  23.                 else if (userInput == exitCommand)
  24.                 {
  25.                     isRunning = false;
  26.                 }
  27.                 else
  28.                 {
  29.                     int userNumber;
  30.                     int[] tempArray;
  31.  
  32.                     if (int.TryParse(userInput, out userNumber))
  33.                     {
  34.                         tempArray = new int[array.Length + 1];
  35.  
  36.                         for (int i = 0; i < array.Length; i++)
  37.                         {
  38.                             tempArray[i] = array[i];
  39.                         }
  40.  
  41.                         tempArray[tempArray.Length - 1] = userNumber;
  42.                         array = tempArray;
  43.  
  44.                         Console.WriteLine("Введено число " + userNumber);
  45.                     }
  46.                     else
  47.                     {
  48.                         Console.WriteLine("Неверный ввод команды!");
  49.                     }
  50.                 }
  51.             }
  52.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement