Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _2_Сshrp_L
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isWork = true;
- int[] array = new int[0];
- string userCommand = " ";
- string comand = " ";
- while (isWork == true)
- {
- Console.WriteLine("Команды: \nВведите sum для суммы чисел\nВведите sort для сортировки\nВведите exit для выхода\nВведите число:");
- comand = Console.ReadLine();
- if (comand == "sum" || comand == "sort" || comand == "exit")
- {
- userCommand = comand;
- }
- int sum = 0;
- switch (userCommand)
- {
- case "sum":
- for (int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- }
- Console.WriteLine("Сумма элементов " + sum);
- userCommand = " ";
- break;
- case "sort":
- int buf;
- for (int i = 0; i < array.Length - 1; i++)
- {
- for (int j = i + 1; j < array.Length; j++)
- {
- if (array[i] > array[j])
- {
- buf = array[i];
- array[i] = array[j];
- array[j] = buf;
- }
- }
- }
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- userCommand = " ";
- break;
- case "exit":
- isWork = false;
- break;
- default:
- int[] tempArray = new int[array.Length + 1];
- tempArray[tempArray.Length - 1] = Convert.ToInt32(comand);
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- array = tempArray;
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment