kwest87

Untitled

Dec 18th, 2023
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 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[] array = 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 < array.Length; i++)
  27.                     {
  28.                         sumNumber += array[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[array.Length + 1];
  40.                     temporaryArray[array.Length] = Convert.ToInt32(userInput);
  41.  
  42.                     for (int i = 0; i < array.Length; i++)
  43.                     {
  44.                         temporaryArray[i] = array[i];
  45.                     }
  46.  
  47.                     array = temporaryArray;
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
  53. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment