-
-
Save StrikerXx798/d3f6a88641672c1722417187b78bd2ee to your computer and use it in GitHub Desktop.
ДЗ: Динамический массив продвинутый
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace ConsoleApp1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.InputEncoding = Encoding.Unicode; | |
Console.OutputEncoding = Encoding.Unicode; | |
const string ExitCommand = "exit"; | |
const string SumCommand = "sum"; | |
bool isRun = true; | |
List<int> numbers = new List<int>(); | |
while (isRun) | |
{ | |
Console.Write("Текущий массив чисел: "); | |
foreach (int number in numbers) | |
{ | |
Console.Write($"{number} "); | |
} | |
Console.WriteLine(); | |
Console.Write("Введите команду: "); | |
string command = Console.ReadLine(); | |
switch (command) | |
{ | |
case SumCommand: | |
int sum = 0; | |
foreach (int number in numbers) | |
{ | |
sum += number; | |
} | |
Console.WriteLine($"Сумма значений из массива: {sum}"); | |
break; | |
case ExitCommand: | |
isRun = false; | |
Console.WriteLine("Вы вышли из программы."); | |
break; | |
default: | |
if (string.IsNullOrEmpty(command)) | |
{ | |
Console.WriteLine("Вы не ввели команду."); | |
break; | |
} | |
if (int.TryParse(command, out int parsedNumber)) | |
{ | |
numbers.Add(parsedNumber); | |
} | |
else | |
{ | |
Console.WriteLine("Вы ввели не число."); | |
} | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment