Last active
July 10, 2025 07:55
-
-
Save Nikolay-Shved/9be546038960e4a1e469b2962bdc4bd2 to your computer and use it in GitHub Desktop.
ДЗ: Динамический массив
This file contains hidden or 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; | |
namespace Dynamic_array | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string CommandSum = "sum"; | |
const string CommandExit = "exit"; | |
int[] numbers = new int[0]; | |
string desiredOperation; | |
bool isWork = true; | |
Console.WriteLine($"{CommandSum} - Сложить все введенные числа."); | |
Console.WriteLine($"{CommandExit} - Закрыть программу"); | |
while (isWork) | |
{ | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
Console.Write(numbers[i] + " "); | |
} | |
Console.Write("\n\nВыберите нужную опцию или введите число:\n"); | |
desiredOperation = Console.ReadLine(); | |
switch (desiredOperation) | |
{ | |
case CommandSum: | |
int sum = 0; | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
sum += numbers[i]; | |
} | |
Console.WriteLine("\nСумма введенных чисел: " + sum); | |
break; | |
case CommandExit: | |
isWork = false; | |
break; | |
default: | |
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(desiredOperation); | |
numbers = tempNumbers; | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment