Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Clight_13_EnterUderWord
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool openMenu = true;
- int stepNumUser = 0;
- string currentWord = "";
- int currentNum;
- string[] wordsUser = new string[0];
- int[] numUser = new int[0];
- int tempElement;
- while (openMenu == true)
- {
- Console.SetCursorPosition(0, 20);
- Console.Write(" sum - выводит сумму введенных значений\n" +
- " sort - выводит значения по возрастанию (только для чисел)\n" +
- " del - удаляет (обнуляет) ввод\n" +
- " exit - выход");
- Console.SetCursorPosition(0, 0);
- Console.Write($"Введи своё {stepNumUser + 1} значение: ");
- currentWord = Console.ReadLine();
- if (currentWord == "sum")
- {
- int sum = 0;
- for (int i = 0; i < numUser.Length; i++)
- {
- sum += numUser[i];
- }
- Console.Write("\n\nВаши значения: ");
- for (int i = 0; i < numUser.Length; i++)
- {
- Console.Write(numUser[i] + ", ");
- }
- Console.Write("\n\nСумма значений: " + sum);
- Console.ReadKey();
- }
- else
- {
- if (currentWord == "sort")
- {
- // Сортировка по возрастанию.
- int[] numSortUser = new int[numUser.Length];
- for (int i = 0; i < numSortUser.Length; i++)
- {
- numSortUser[i] = numUser[i];
- }
- int stepLenght = 0;
- for (int j = 0; j < numSortUser.Length - 1; j++)
- {
- for (int i = 0; i < numSortUser.Length - 1 - stepLenght; i++)
- {
- if (numSortUser[i] > numSortUser[i + 1])
- {
- tempElement = numSortUser[i + 1];
- numSortUser[i + 1] = numSortUser[i];
- numSortUser[i] = tempElement;
- }
- }
- stepLenght++;
- }
- Console.Write("\n\nВаши отсортированные значения: ");
- for (int i = 0; i < numSortUser.Length; i++)
- {
- Console.Write(numSortUser[i] + ", "); // Как избавиться от последней не нужной запятой при выводе sum?
- }
- Console.ReadKey();
- }
- else
- {
- if (currentWord == "del")
- {
- // Обнуление массива
- numUser = new int[0];
- stepNumUser = 0;
- }
- else
- {
- if (currentWord == "exit")
- {
- openMenu = false;
- }
- else
- {
- // Заполняем массив по мере ввода пользователем.
- currentNum = Convert.ToInt32(currentWord);
- int[] numTemp = new int[numUser.Length + 1];
- for (int i = 0; i < numUser.Length; i++)
- {
- numTemp[i] = numUser[i];
- }
- numTemp[numTemp.Length - 1] = currentNum;
- numUser = numTemp;
- stepNumUser++;
- }
- }
- }
- }
- Console.Clear();
- }
- Console.WriteLine("\n\nЖдем вас снова!");
- Console.Write("\nВаша последовательность напоследок: ");
- for (int i = 0; i < numUser.Length; i++)
- {
- Console.Write(numUser[i] + ", "); // Как избавиться от последней не нужной запятой при выводе sum?
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement