Created
December 3, 2024 17:20
-
-
Save HunvejBeen/9017ed7ac00652d1349e7f254866604a 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.Collections.Generic; | |
namespace DZ_3 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<int> numbers = new List<int>(); | |
int sumNumbers = 0; | |
string commandExit = "exit"; | |
string commandSum = "sum"; | |
bool isOpen = true; | |
while (isOpen) | |
{ | |
PrintList(numbers); | |
Console.Write("\nВведите sum чтобы вывести сумму списка\nВведите exit чтобы выйти\nВведите число чтобы добавить его в список: "); | |
string command = Console.ReadLine(); | |
if(int.TryParse(command, out int newNumber)) | |
{ | |
numbers.Add(newNumber); | |
sumNumbers += newNumber; | |
} | |
else if (command == commandExit) | |
{ | |
isOpen = false; | |
} | |
else if(command == commandSum) | |
{ | |
Console.Write($"\nСумма чисел в списке = {sumNumbers}"); | |
} | |
Console.ReadLine(); | |
Console.Clear(); | |
} | |
} | |
static void PrintList(List<int> list) | |
{ | |
foreach (int i in list) | |
{ | |
Console.Write(i + " "); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment