Skip to content

Instantly share code, notes, and snippets.

@Ana19997
Created October 3, 2021 11:28
Show Gist options
  • Save Ana19997/557f74c1cafbd5d867a02ae56b6a832d to your computer and use it in GitHub Desktop.
Save Ana19997/557f74c1cafbd5d867a02ae56b6a832d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace сум
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
string count = "sum";
string exit = "exit";
string userInput = "";
int[] Data = new int[0];
Console.WriteLine("Введите элемент массива");
while (true)
{
userInput = Console.ReadLine();
switch (userInput)
{
case "sum":
Console.WriteLine(String.Format("Сумма элементов = {0}", Data.Sum()));
break;
case "exit":
return;
default:
int result;
if (int.TryParse(userInput, out result))
Data = Data.Concat(new int[] { result }).ToArray();
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment