Created
October 5, 2021 16:53
-
-
Save Ana19997/67220a0497c1fda383511486b5d0b937 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[] increase = new int[data.Length + 1]; | |
for (int i = 0; i < data.Length; i++) | |
{ | |
increase[i] = data[i]; | |
} | |
increase[increase.Length - 1] = data.Length; | |
data = increase; | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment