kwest87

Untitled

Dec 16th, 2023
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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.             string userInput;
  11.             int[] array = new int[0];
  12.             bool isWork = true;
  13.  
  14.             while (isWork)
  15.             {
  16.                 Console.WriteLine("Введите команду : цифру , sum или exit.");
  17.                 userInput = Console.ReadLine();
  18.  
  19.                 if (userInput == "sum")
  20.                 {
  21.                     int sumNumber = 0;
  22.  
  23.                     for (int i = 0; i < array.Length; i++)
  24.                     {
  25.                         sumNumber += array[i];
  26.                     }
  27.  
  28.                     Console.WriteLine(sumNumber);
  29.                 }
  30.                 else if (userInput == "exit")
  31.                 {
  32.                     isWork = false;
  33.                 }
  34.                 else
  35.                 {
  36.                     int[] temporaryArray = new int[array.Length +1];
  37.                     temporaryArray[array.Length ] = Convert.ToInt32(userInput);
  38.  
  39.                     for(int i = 0; i < array.Length; i++)
  40.                     {
  41.                         temporaryArray[i] = array[i];
  42.                     }
  43.  
  44.                     array = temporaryArray;
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
  50. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment