Created
October 6, 2021 12:57
-
-
Save Ana19997/9fb1977ffda5d6bb89072353ffa8edae 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; | |
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