Advertisement
Guest User

3.4

a guest
Feb 23rd, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3._4_Massiv
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isIncluded = true;
  14.             int[] array = new int[0];
  15.             while (isIncluded)
  16.             {
  17.                 Console.SetCursorPosition(0, 0);
  18.                 int[] tempArray = new int[array.Length + 1];
  19.                 Console.Write("Введите число:");
  20.                 for (int i = 0; i < array.Length; i++)
  21.                 {
  22.                     tempArray[i] = array[i];
  23.                     Console.Write(array[i] + ",");  
  24.                 }
  25.                 tempArray[tempArray.Length - 1] = Convert.ToInt32(Console.ReadLine());
  26.                 array = tempArray;
  27.                
  28.                 Console.SetCursorPosition(0, 5);
  29.                 Console.WriteLine("Выберите команду: \nsum - сумма всех введённых чисел; \nsort - программа отсортирует массив; " +
  30.                     "\nexit - выход из программы;\nНажмите любую клавишу для пропуска ввода команды.");
  31.                 string userInput = " ";
  32.                 switch (userInput = Console.ReadLine().ToLower())
  33.                     {
  34.                         case "sum":
  35.                         int sum = 0;
  36.                         for (int i = 0; i < array.Length; i++)
  37.                             {
  38.                                 sum += array[i];
  39.                             }
  40.                         Console.Write("Сумма введённых чисел:" + sum);
  41.                         sum = 0;
  42.                         break;
  43.                         case "sort":
  44.                         for (int i = 0; i < array.Length; i++)
  45.                         {
  46.                             for (int j = 0; j < array.Length - 1; j++)
  47.                             {
  48.                                 if (array[j] > array[j + 1])
  49.                                 {
  50.                                     int sortArray = array[j];
  51.                                     array[j] = array[j + 1];
  52.                                     array[j + 1] = sortArray;
  53.                                 }
  54.                                
  55.                             }
  56.                         }
  57.                         break;
  58.                         case "exit":
  59.                             isIncluded = false;
  60.                             break;
  61.                     }
  62.                 Console.WriteLine("\nНажмите любую клвишу");
  63.                 Console.ReadKey();
  64.                 Console.Clear();
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement