Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HomeWork
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- const string CommandExit = "exit";
- const string CommandSum = "sum";
- int sum = 0;
- int[] initialArray = Array.Empty<int>();
- string userInput = "";
- while (userInput != CommandExit)
- {
- Console.WriteLine($"Введите команду: " +
- $"\n{CommandSum} - сумма чисел" +
- $"\n{CommandExit} - выход из программы\n" +
- "Введите число...\n");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandExit:
- Console.WriteLine("Завершение программы...");
- break;
- case CommandSum:
- foreach(int i in initialArray)
- sum += i;
- Console.WriteLine("Сумма = " + sum + "\n");
- break;
- default:
- if (int.TryParse(userInput, out int number))
- {
- Console.Clear();
- int[] newArray = new int[initialArray.Length + 1];
- for (int i = 0; i < initialArray.Length; i++)
- newArray[i] = initialArray[i];
- newArray[newArray.Length - 1] = number;
- initialArray = newArray;
- }
- else
- {
- Console.WriteLine("Нужно ввести число или одну из вдух команд");
- }
- break;
- }
- }
- Console.WriteLine();
- Console.WriteLine("Числа в массиве:");
- for (int i = 0; i < initialArray.Length; i++)
- Console.Write(initialArray[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement