Advertisement
AlexRaynor

3.7 ArrayExpand

Sep 9th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 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 ConsoleApp12
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {  
  13.  
  14.             String userInput = "";
  15.             int i = 0;
  16.             int[] array = new int[0];
  17.             Console.WriteLine("Введите цифры");
  18.             do
  19.             {
  20.                 userInput = Console.ReadLine();
  21.                 if (userInput == "sum") break;
  22.                 int arrayElement = int.Parse(userInput);
  23.  
  24.                 int[] tempArray = new int[array.Length + 1];
  25.                 for (i = 0; i < array.Length; i++)
  26.                 {
  27.                     tempArray[i] = array[i];
  28.                 }
  29.                 tempArray[tempArray.Length - 1] = arrayElement;
  30.                 array= tempArray;
  31.  
  32.  
  33.             }
  34.             while (true);
  35.             Console.WriteLine("Сумма: ");
  36.             int sum = 0;
  37.             for (int j = 0; j < array.Length; j++)
  38.             {
  39.                 sum += array[j];
  40.             }
  41.  
  42.             Console.WriteLine(sum);
  43.             userInput = Console.ReadLine();
  44.             if (userInput == "sort")
  45.             {
  46.                 Array.Sort(array);
  47.                 Array.Reverse(array);
  48.                 Console.WriteLine();
  49.                 for (int p = 0; p < array.Length; p++)
  50.                 {
  51.                     Console.Write(array[p] + " ");
  52.                 }
  53.             }
  54.  
  55.  
  56.  
  57.  
  58.             //
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement