Skip to content

Instantly share code, notes, and snippets.

@Dnk095
Last active May 12, 2024 10:26
Show Gist options
  • Save Dnk095/fc7a2c625088e57361b0e7e54db92099 to your computer and use it in GitHub Desktop.
Save Dnk095/fc7a2c625088e57361b0e7e54db92099 to your computer and use it in GitHub Desktop.
using System;
namespace _3_4
{
internal class Program
{
static void Main()
{
const string CommandSumAll = "Sum";
const string CommandExit = "Exit";
int[] numbers = new int[0];
int sum=0;
string inputData;
bool isWorking = true;
while (isWorking)
{
Console.WriteLine($"Введите число или {CommandSumAll} для суммирования всех чисел в массиве или {CommandExit} для выхода");
inputData = Console.ReadLine();
switch (inputData)
{
case CommandSumAll:
Console.Clear();
foreach (int number in numbers)
{
sum += number;
}
Console.WriteLine($"Сумма всех чисел в массиве= {sum}");
sum = 0;
break;
case CommandExit:
Console.Clear();
isWorking = false;
break;
default:
Console.Clear();
int[] temporarilyNumbers = new int[numbers.Length+1];
for (int i = 0;i<numbers.Length;i++)
{
temporarilyNumbers[i] = numbers[i];
}
temporarilyNumbers[temporarilyNumbers.Length - 1] = Convert.ToInt32(inputData);
numbers = temporarilyNumbers;
break;
}
Console.WriteLine("Цифры в введенном масcиве: ");
for (int i = 0; i < numbers.Length;i++)
{
Console.Write(numbers[i]+" ");
}
Console.WriteLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment