kwest87

Untitled

Dec 20th, 2023
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3.  
  4. namespace ConsoleApp14
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             const string CommandSum = "sum";
  11.             const string CommandExit = "exit";
  12.  
  13.             string userInput;
  14.             int[] numbers = new int[0];
  15.             bool isWork = true;
  16.  
  17.             while (isWork)
  18.             {
  19.                 Console.WriteLine($"Введите команду : цифру , {CommandSum} или {CommandExit}.");
  20.                 userInput = Console.ReadLine();
  21.  
  22.                 if (userInput == CommandSum)
  23.                 {
  24.                     int sumNumber = 0;
  25.  
  26.                     for (int i = 0; i < numbers.Length; i++)
  27.                     {
  28.                         sumNumber += numbers[i];
  29.                     }
  30.  
  31.                     Console.WriteLine(sumNumber);
  32.                 }
  33.                 else if (userInput == CommandExit)
  34.                 {
  35.                     isWork = false;
  36.                 }
  37.                 else
  38.                 {
  39.                     int[] temporaryArray = new int[numbers.Length + 1];
  40.                     temporaryArray[numbers.Length] = Convert.ToInt32(userInput);
  41.  
  42.                     for (int i = 0; i < numbers.Length; i++)
  43.                     {
  44.                         temporaryArray[i] = numbers[i];
  45.                     }
  46.  
  47.                     numbers = temporaryArray;
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
  53. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment