Skip to content

Instantly share code, notes, and snippets.

@Ana19997
Created October 6, 2021 12:57
Show Gist options
  • Save Ana19997/9fb1977ffda5d6bb89072353ffa8edae to your computer and use it in GitHub Desktop.
Save Ana19997/9fb1977ffda5d6bb89072353ffa8edae 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)
{
string userInput = "";
int[] data = new int[0];
Console.WriteLine("Введите элемент массива");
while (userInput != "exit")
{
userInput = Console.ReadLine();
switch (userInput)
{
case "sum":
int sum = 0;
for (int i = 0; i < data.Length; i++)
{
sum += data[i];
}
Console.WriteLine("Сумма введённых чисел равна " + sum);
break;
case "exit":
return;
default:
int[] extendedData = new int[data.Length + 1];
for (int i = 0; i < data.Length; i++)
{
extendedData[i] = data[i];
}
extendedData[extendedData.Length - 1] = Convert.ToInt32(userInput);
data = extendedData;
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment