-
-
Save Dnk095/fc7a2c625088e57361b0e7e54db92099 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; | |
namespace _3_4 | |
{ | |
internal class Program | |
{ | |
static void Main() | |
{ | |
const string CommandSumAll = "Sum"; | |
const string CommandExit = "Exit"; | |
int[] numbers = new int[0]; | |
int sum=0; | |
string inputData; | |
bool isWorking = true; | |
while (isWorking) | |
{ | |
Console.WriteLine($"Введите число или {CommandSumAll} для суммирования всех чисел в массиве или {CommandExit} для выхода"); | |
inputData = Console.ReadLine(); | |
switch (inputData) | |
{ | |
case CommandSumAll: | |
Console.Clear(); | |
foreach (int number in numbers) | |
{ | |
sum += number; | |
} | |
Console.WriteLine($"Сумма всех чисел в массиве= {sum}"); | |
sum = 0; | |
break; | |
case CommandExit: | |
Console.Clear(); | |
isWorking = false; | |
break; | |
default: | |
Console.Clear(); | |
int[] temporarilyNumbers = new int[numbers.Length+1]; | |
for (int i = 0;i<numbers.Length;i++) | |
{ | |
temporarilyNumbers[i] = numbers[i]; | |
} | |
temporarilyNumbers[temporarilyNumbers.Length - 1] = Convert.ToInt32(inputData); | |
numbers = temporarilyNumbers; | |
break; | |
} | |
Console.WriteLine("Цифры в введенном масcиве: "); | |
for (int i = 0; i < numbers.Length;i++) | |
{ | |
Console.Write(numbers[i]+" "); | |
} | |
Console.WriteLine(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment