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 Динамический_массив
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int [2];
- string userInput;
- int sum = 0;
- bool exit = true;
- Console.Write("Введите 1 число:");
- array[0] = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите 2 число:");
- array[1] = Convert.ToInt32(Console.ReadLine());
- while (exit)
- {
- Console.Clear();
- Console.WriteLine("sum - сумма введённых чисел.");
- Console.WriteLine("sort - сортирование массива.");
- Console.WriteLine("exit - выход.");
- Console.Write("Введите команду:");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "sum":
- Console.Clear();
- for(int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- }
- Console.WriteLine($"Сумма чисел равна {sum}");
- sum = 0;
- Console.ReadKey();
- break;
- case "sort":
- Console.Clear();
- Console.WriteLine("Ваш массив");
- for (int j = 0; j < array.Length; j++)
- {
- Console.Write(array[j] + " ");
- }
- Console.ReadKey();
- break;
- }
- if(userInput == "exit")
- {
- exit = false;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement