Skip to content

Instantly share code, notes, and snippets.

@HunvejBeen
Created December 3, 2024 17:20
Show Gist options
  • Save HunvejBeen/9017ed7ac00652d1349e7f254866604a to your computer and use it in GitHub Desktop.
Save HunvejBeen/9017ed7ac00652d1349e7f254866604a to your computer and use it in GitHub Desktop.
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