Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Homework3_4
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandSum = "sum";
- const string CommandExit = "exit";
- string desiredOperation = "";
- int[] numbers = new int[] { };
- int number;
- bool isRunning = true;
- Console.WriteLine("Заполните масив числами: ");
- while (isRunning)
- {
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.Write(numbers[i] + " ");
- }
- Console.WriteLine("\nВведите число или команду.");
- Console.WriteLine($"{CommandSum} - Вывести сумму всех веденных чисел.");
- Console.WriteLine($"{CommandExit} - Выйти из программы.");
- Console.Write("Ваш выбор: ");
- desiredOperation = Console.ReadLine();
- switch (desiredOperation)
- {
- case CommandSum:
- int sum = 0;
- for (int i = 0; i < numbers.Length; i++)
- {
- sum += numbers[i];
- }
- Console.WriteLine("\nСумма всех веденных чисел: " + sum);
- break;
- case CommandExit:
- isRunning = false;
- break;
- default:
- number = Convert.ToInt32(desiredOperation);
- int[] tempNumbers = new int[numbers.Length + 1];
- for (int i = 0; i < numbers.Length; i++)
- {
- tempNumbers[i] = numbers[i];
- }
- tempNumbers[tempNumbers.Length - 1] = number;
- numbers = tempNumbers;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement