Advertisement
Guest User

Untitled

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