Skip to content

Instantly share code, notes, and snippets.

@Mister7184
Last active May 29, 2025 16:07
Show Gist options
  • Save Mister7184/3607f2d750f127a29b3114d5f54b0be0 to your computer and use it in GitHub Desktop.
Save Mister7184/3607f2d750f127a29b3114d5f54b0be0 to your computer and use it in GitHub Desktop.
ДЗ: Динамический массив
using System;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
int[] numbers = new int[0];
string userInput;
string sumCommand = "sum";
string exitCommand = "exit";
bool isWork = true;
while (isWork)
{
Console.Write("Числа: ");
for (int i = 0; i < numbers.Length; i++)
{
Console.Write(numbers[i] + " ");
}
Console.WriteLine($"\nВведите число или слова {sumCommand}, {exitCommand} ");
userInput = Console.ReadLine();
if (userInput == sumCommand)
{
int totalSum = 0;
for (int i = 0; i < numbers.Length; i++)
{
totalSum += numbers[i];
}
Console.WriteLine($"Сумма всех чисел: {totalSum}");
}
else if (userInput == exitCommand)
{
Console.WriteLine("Работа завершена");
isWork = false;
}
else
{
int[] tempNumbers = new int[numbers.Length + 1];
for (int i = 0; i < numbers.Length; i++)
{
tempNumbers[i] = numbers[i];
}
tempNumbers[tempNumbers.Length - 1] = Convert.ToInt32(userInput);
numbers = tempNumbers;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment