Advertisement
CrewLab

day 03_7

May 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 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 Les3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] arr = new int[0];
  14.             string tmp_s;
  15.  
  16.             Console.Write("Введите по очереди необходимые вам числа.\nЕсли вы хотите получить сумму этих чисел, напишите команду \"sum\".\n" +
  17.                 "Eсли вы хотите увидеть введеные вами числа в порядке убывания напишите команду \"sort\"\nДля выхода введите \"exit\".\n");
  18.             while (true)
  19.             {
  20.                 Console.Write("Введите число или команду: ");
  21.                 tmp_s = Console.ReadLine();
  22.                 if(tmp_s != "sum" && tmp_s != "sort")
  23.                 {
  24.                     int[] tmpInt = new int[arr.Length + 1];
  25.                     for (int i = 0; i < arr.Length; i++)
  26.                         tmpInt[i] = arr[i];
  27.                     tmpInt[tmpInt.Length - 1] = Convert.ToInt32(tmp_s);
  28.                     arr = tmpInt;
  29.                 }
  30.                 if (tmp_s == "sum")
  31.                 {
  32.                     int sum = 0;
  33.                     for (int i = 0; i < arr.Length; i++)
  34.                     {
  35.                         sum += arr[i];
  36.                     }
  37.                     Console.WriteLine();
  38.                     Console.Clear();
  39.                     Console.Write("Сумма введеных вами чисел равна " + sum + ".\n");
  40.                 }
  41.                 if (tmp_s == "sort")
  42.                 {
  43.                     int tmp;
  44.                     for (int i = 0; i < arr.Length; i++)
  45.                     {
  46.                         for (int j = 0; j < arr.Length; j++)
  47.                         {
  48.                             if (j != arr.Length - 1 && arr[j] < arr[j + 1])
  49.                             {
  50.                                 tmp = arr[j];
  51.                                 arr[j] = arr[j + 1];
  52.                                 arr[j + 1] = tmp;
  53.                             }
  54.                         }
  55.                     }
  56.                     Console.Clear();
  57.                     Console.Write("Вы ввели следующие числа: ");
  58.                     for (int i = 0; i < arr.Length; i++)
  59.                     {
  60.                         if (i < arr.Length - 1)
  61.                             Console.Write(arr[i] + " ");
  62.                         else
  63.                             Console.Write(arr[i]);
  64.                     }
  65.                     Console.WriteLine(".");
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement