Advertisement
Anonim_999

Untitled

Jan 9th, 2021 (edited)
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp9
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int sum;
  10.             bool isWork = true;
  11.             string userInput;
  12.             int[] array = new int[0];
  13.  
  14.             while (isWork)
  15.             {
  16.                 Console.Clear();
  17.                 Console.WriteLine("Комманды:\nexit\nsum\nПишите цифры я их запомню, и сумирую если попросите)");
  18.                 userInput = Console.ReadLine();
  19.  
  20.                 switch (userInput)
  21.                 {
  22.                     case "exit":
  23.                         isWork = false;
  24.                         break;
  25.                     case "sum":
  26.                         sum = 0;
  27.  
  28.                         for (int i = 0; i < array.Length; i++)
  29.                         {
  30.                             sum += array[i];
  31.                             Console.Write($"{array[i]} ");
  32.                         }
  33.  
  34.                         Console.WriteLine($"\nСумма введенных чисел: {sum}\nНажмите любую клавишу для продолжения...");
  35.                         Console.ReadKey();
  36.                         break;
  37.                     default:
  38.                         int[] tempArray = new int[array.Length + 1];
  39.  
  40.                         for (int i = 0; i < array.Length; i++)
  41.                         {
  42.                             tempArray[i] = array[i];
  43.                         }
  44.  
  45.                         tempArray[tempArray.Length - 1] = Convert.ToInt32(userInput);
  46.                         array = tempArray;
  47.                         break;
  48.                 }
  49.             }
  50.  
  51.             Console.ReadKey();
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement