Last active
June 28, 2024 10:58
-
-
Save MagSosiq/f66bfbe8bf552db21259a3e140bd4092 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.Text; | |
namespace HW1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.InputEncoding = Encoding.Unicode; | |
Console.OutputEncoding = Encoding.Unicode; | |
const string CommandSum = "sum"; | |
const string CommandExit = "exit"; | |
int[] numbers = new int[0]; | |
bool isWorking = true; | |
while (isWorking) | |
{ | |
Console.Write("Текущие числа: "); | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
Console.Write(numbers[i] + " "); | |
} | |
Console.WriteLine(); | |
string input = Console.ReadLine(); | |
switch (input) | |
{ | |
case CommandSum: | |
int numbersSum = 0; | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
numbersSum += numbers[i]; | |
} | |
Console.WriteLine("Сумма чисел массива: " + numbersSum); | |
break; | |
case CommandExit: | |
Console.WriteLine("Произошёл выход из программы!"); | |
isWorking = false; | |
break; | |
default: | |
if (int.TryParse(input, out int number)) | |
{ | |
int[] newNumbers = new int[numbers.Length + 1]; | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
newNumbers[i] = numbers[i]; | |
} | |
newNumbers[numbers.Length] = number; | |
numbers = newNumbers; | |
} | |
else | |
{ | |
Console.WriteLine("Некорректный ввод. Пожалуйста, введите число, 'sum' или 'exit'."); | |
} | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment