Last active
April 29, 2024 05:54
-
-
Save kyzalex/a69d5ff93215cb12df291bd7f1dd4240 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
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<int> numbers = new List<int>(); | |
string inputSumm = "summ"; | |
string inputExit = "exit"; | |
bool isOpen = true; | |
while (isOpen) | |
{ | |
Console.WriteLine($"Введите число для записи его в программе \nвведите комаду {inputSumm} - сложить числа в программу \nвведите команду {inputExit} - выйти из программы "); | |
Console.Write("Введите данные : "); | |
string userInput = Console.ReadLine(); | |
if (userInput == inputSumm) | |
{ | |
CalculateQuantity(numbers, out int summ); | |
} | |
else if (userInput == inputExit) | |
{ | |
isOpen = false; | |
} | |
else if ((int.TryParse(userInput, out int result))) | |
{ | |
numbers.Add(result); | |
} | |
else | |
{ | |
Console.WriteLine("Вы ввели неправильное значение"); | |
} | |
foreach (int number in numbers) | |
{ | |
Console.WriteLine(number); | |
} | |
Console.WriteLine("Нажмите для продолжения"); | |
Console.ReadKey(); | |
Console.Clear(); | |
} | |
} | |
static void CalculateQuantity(List<int> numbers, out int summOfNumbers) | |
{ | |
summOfNumbers = 0; | |
foreach (int number in numbers) | |
{ | |
summOfNumbers += number; | |
} | |
Console.WriteLine("Сумма = " + summOfNumbers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment