Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Lesson3_6
- {
- class Program
- {
- static void Main(string[] args)
- {
- var array = new int[0];
- var arrayComands = new string[3] { "sum" , "sort" , "exit" };
- Console.WriteLine($"Вывод суммы: \"{arrayComands[0]}\"\n" +
- $"Вывод чисел в порядке убывания: \"{arrayComands[1]}\"\n" +
- $"Выход из программы: \"{arrayComands[2]}\"\n");
- while(true)
- {
- Console.Write("Введите число(команду): ");
- string userInput = Console.ReadLine().ToLower();
- if (userInput == arrayComands[0])
- {
- int sumNumbers = 0;
- for (int i = 0; i < array.Length; i++)
- {
- sumNumbers += array[i];
- }
- Console.WriteLine($"\nСумма чисел: {sumNumbers} \n");
- }
- else if (userInput == arrayComands[1])
- {
- Console.WriteLine($"\nПорядок чисел по убыванию:");
- int reserveNumber;
- for (int j = 1; j < array.Length; j++)
- {
- for (int i = 0; i < array.Length - j; i++)
- {
- if (array[i] < array[i + 1])
- {
- reserveNumber = array[i];
- array[i] = array[i + 1];
- array[i + 1] = reserveNumber;
- }
- }
- }
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine("\n");
- }
- else if (userInput == arrayComands[2])
- {
- break;
- }
- else
- {
- int inputNumber = Convert.ToInt32(userInput);
- var arrayNew = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- arrayNew[i] = array[i];
- }
- arrayNew[array.Length] = inputNumber;
- array = arrayNew;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment