Advertisement
Ash_HeLiX

Day3Home6

Oct 14th, 2019
148
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. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Home6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string message = " ";
  14.             bool isSum = false;
  15.             int arraySum = 0;
  16.             int[] array = new int[0];
  17.            
  18.  
  19.             do
  20.             {
  21.                 message = Console.ReadLine();
  22.                 switch (message)
  23.                 {
  24.                     case "sum":
  25.                         for (int i = 0; i < array.Length; i++)
  26.                         {
  27.                             arraySum += array[i];
  28.                         }
  29.                         isSum = true;
  30.                         break;
  31.                     default:
  32.                         int[] tempArray = new int[array.Length + 1];
  33.                         for (int i = 0; i < array.Length; i++)
  34.                         {
  35.                             tempArray[i] = array[i];
  36.                         }
  37.                         tempArray[tempArray.Length-1] = Convert.ToInt32(message);
  38.                         array = tempArray;
  39.                         break;
  40.                 }
  41.             } while (isSum != true);
  42.             Console.WriteLine(arraySum);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement