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 Les3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = new int[0];
- string tmp_s;
- Console.Write("Введите по очереди необходимые вам числа.\nЕсли вы хотите получить сумму этих чисел, напишите команду \"sum\".\n" +
- "Eсли вы хотите увидеть введеные вами числа в порядке убывания напишите команду \"sort\"\nДля выхода введите \"exit\".\n");
- while (true)
- {
- Console.Write("Введите число или команду: ");
- tmp_s = Console.ReadLine();
- if(tmp_s != "sum" && tmp_s != "sort")
- {
- int[] tmpInt = new int[arr.Length + 1];
- for (int i = 0; i < arr.Length; i++)
- tmpInt[i] = arr[i];
- tmpInt[tmpInt.Length - 1] = Convert.ToInt32(tmp_s);
- arr = tmpInt;
- }
- if (tmp_s == "sum")
- {
- int sum = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- sum += arr[i];
- }
- Console.WriteLine();
- Console.Clear();
- Console.Write("Сумма введеных вами чисел равна " + sum + ".\n");
- }
- if (tmp_s == "sort")
- {
- int tmp;
- for (int i = 0; i < arr.Length; i++)
- {
- for (int j = 0; j < arr.Length; j++)
- {
- if (j != arr.Length - 1 && arr[j] < arr[j + 1])
- {
- tmp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = tmp;
- }
- }
- }
- Console.Clear();
- Console.Write("Вы ввели следующие числа: ");
- for (int i = 0; i < arr.Length; i++)
- {
- if (i < arr.Length - 1)
- Console.Write(arr[i] + " ");
- else
- Console.Write(arr[i]);
- }
- Console.WriteLine(".");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement