voldmaks

Динамический массив (продвинутый)

Jul 21st, 2021 (edited)
1,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 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 ConsoleApp5
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = new List<int>();
  14.             bool cycleWork = true;
  15.  
  16.             while (cycleWork)
  17.             {
  18.                 int sumOfNumbers = 0;
  19.                 string userInput = Console.ReadLine();
  20.  
  21.                 if (userInput == "exit")
  22.                 {
  23.                     cycleWork = false;
  24.                 }
  25.                 else if (userInput == "sum")
  26.                 {
  27.                     for (int i = 0; i < numbers.Count; i++)
  28.                     {
  29.                         sumOfNumbers += numbers[i];
  30.                     }
  31.                     Console.WriteLine($"Сумма чисел равна: {sumOfNumbers}");
  32.                 }
  33.                 else
  34.                 {
  35.                     numbers.Add(int.Parse(userInput));
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
Add Comment
Please, Sign In to add comment