Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Study
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Введите количество элементов массива:\t");
- bool exit=true;
- int elementsCount = int.Parse(Console.ReadLine());
- int[] myArray = new int[elementsCount];
- int sum=0,temp;
- string Command;
- for (int i = 0; i < myArray.Length; i++)
- {
- Console.Write($"Введите элемент массива под индексом {i}:\t");
- myArray[i] = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("Исходный массив");
- for (int i = 0; i < myArray.Length; i++)
- {
- Console.Write(myArray[i]+" ");
- }
- Console.WriteLine();
- while (exit) {
- Console.WriteLine("Введите команду");
- Console.WriteLine("Введите SUM для сложения элементов массива.Введите SORT для сортировки массива. Введите ESC для выхода из программы");
- Command = Console.ReadLine();
- switch (Command)
- {
- case "SUM":
- for (int i = 0; i < myArray.Length; i++)
- {
- sum += myArray[i];
- }
- Console.WriteLine(sum);
- break;
- case "SORT":
- for (int i = 0; i < myArray.Length; i++)
- {
- for (int j=i;j<myArray.Length;j++)
- if (myArray[j] < myArray[i])
- {
- temp = myArray[i];
- myArray[i] = myArray[j];
- myArray[j] = temp;
- }
- }
- Console.WriteLine();
- Console.Write("Массив после сортировки:\t");
- for (int i = 0; i < myArray.Length; i++)
- {
- Console.Write(myArray[i] + " ");
- }
- break;
- case "ESC":
- exit = false;
- break;
- }
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement