Advertisement
VoVfe

Untitled

Mar 23rd, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 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 Динамический_массив
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = new int [2];
  14.             string userInput;
  15.             int sum = 0;
  16.             bool exit = true;
  17.  
  18.             Console.Write("Введите 1 число:");
  19.             array[0] = Convert.ToInt32(Console.ReadLine());
  20.             Console.Write("Введите 2 число:");
  21.             array[1] = Convert.ToInt32(Console.ReadLine());
  22.            
  23.             while (exit)
  24.             {
  25.                 Console.Clear();
  26.                 Console.WriteLine("sum - сумма введённых чисел.");
  27.                 Console.WriteLine("sort - сортирование массива.");
  28.                 Console.WriteLine("exit - выход.");
  29.                 Console.Write("Введите команду:");
  30.                 userInput = Console.ReadLine();
  31.          
  32.                 switch (userInput)
  33.                 {
  34.                     case "sum":
  35.                         Console.Clear();
  36.                         for(int i = 0; i < array.Length; i++)
  37.                         {
  38.                             sum += array[i];
  39.                         }
  40.                         Console.WriteLine($"Сумма чисел равна {sum}");
  41.                         sum = 0;
  42.                         Console.ReadKey();
  43.                         break;
  44.                     case "sort":
  45.                         Console.Clear();
  46.                         Console.WriteLine("Ваш массив");
  47.                         for (int j = 0; j < array.Length; j++)
  48.                         {
  49.                         Console.Write(array[j] + " ");
  50.                         }
  51.                         Console.ReadKey();
  52.                         break;
  53.                 }
  54.  
  55.                 if(userInput == "exit")
  56.                 {
  57.                     exit = false;
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement