Advertisement
nikitaTheSlayer

Lesson: array4

Apr 11th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSLight3
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[0];
  10.             int summ = 0;
  11.             string input;            
  12.  
  13.             while (true)
  14.             {
  15.                 input = Console.ReadLine();
  16.  
  17.                 switch (input)
  18.                 {
  19.                     case "sum":
  20.                         for (int i = 0; i < array.Length; i++)
  21.                         {
  22.                             summ += array[i];
  23.                         }
  24.                         Console.WriteLine("Сумма введенных чисел равна: " + summ);
  25.                         summ = 0;
  26.                         break;
  27.                     case "exit":
  28.                         Environment.Exit(0);
  29.                         break;
  30.                     default:
  31.                         int[] tempArray = new int[array.Length + 1];
  32.                         for (int i = 0; i < array.Length; i++)
  33.                         {
  34.                             tempArray[i] = array[i];
  35.                         }
  36.                         tempArray[tempArray.Length - 1] = Convert.ToInt32(input);
  37.                         array = tempArray;
  38.                         break;
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement