Advertisement
dmitryEfremov

Untitled

Apr 14th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp5
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.  
  8.         {
  9.             bool exit = true;
  10.             int[] array = new int[0];
  11.             int sum = 0;
  12.             while (exit)
  13.             {
  14.                 Console.WriteLine("Заполните массив любыми цифрами.\n Как только вы напишите sum программа посчитает сумму ваших чисел.\n Как только вы напишите EXIT программа завершиться.");
  15.                 string command = Console.ReadLine().ToLower();
  16.                 switch (command)
  17.                 {
  18.                     case "exit":
  19.                         exit = false;
  20.                         break;
  21.                     case "sum":
  22.                         Console.WriteLine("Сумма массива:");
  23.                         for(int i = 0; i < array.Length; i++)
  24.                         {
  25.                             Console.Write(array[i]+" ");
  26.                         }
  27.                         for (int i = 0; i < array.Length; i++)
  28.                         {
  29.                             sum +=array[i];
  30.                         }
  31.                         Console.WriteLine($"\nРавна = {sum}");
  32.                         Console.ReadLine();
  33.                         break;
  34.                     default:
  35.                         int[] arrayExtensions = new int[array.Length + 1];
  36.                         arrayExtensions[array.Length] = Convert.ToInt32(command);
  37.                         for (int i = 0; i < array.Length; i++)
  38.                         {
  39.                             arrayExtensions[i] = array[i];
  40.                         }
  41.                         array = arrayExtensions;                        
  42.                         break;
  43.                 }
  44.                 Console.Clear();
  45.             }                
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement