Advertisement
LeRoY_Go

Untitled

Jan 29th, 2022
1,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace C_Sharp_Junior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[0];
  10.             bool isExit = true;
  11.             while (isExit)
  12.             {
  13.                 Console.Write("Ввидите число или слово:");
  14.                 string userInput = Console.ReadLine();
  15.                 if (userInput == "exit")
  16.                 {
  17.                     isExit = false;
  18.                 }
  19.                 else if (userInput == "sum")
  20.                 {
  21.                     int sum = 0;
  22.                     for (int i = 0; i < array.Length; i++)
  23.                     {
  24.                         sum += array[i];
  25.                     }
  26.                     Console.WriteLine("Сумма введённых чисел равна: " + sum);
  27.                 }
  28.                 else
  29.                 {
  30.                     int[] tempArray = new int[array.Length + 1];
  31.                     int number = Convert.ToInt32(userInput);
  32.                     tempArray[tempArray.Length - 1] = number;
  33.                     for (int i = 0; i < array.Length; i++)
  34.                     {
  35.                         tempArray[i] = array[i];
  36.                     }
  37.                     array = tempArray;
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement