Fle2x

HW-5.3

Jun 15th, 2021 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             bool exit = false;
  11.             List<int> nums = new List<int>();
  12.             while (!exit)
  13.             {
  14.                 string input = Console.ReadLine();
  15.                 switch (input)
  16.                 {
  17.                     case "exit":
  18.                         exit = true;
  19.                         break;
  20.                     case "sum":
  21.                         int sum = 0;
  22.                         foreach (var num in nums)
  23.                         {
  24.                             sum += num;
  25.                         }
  26.  
  27.                         Console.WriteLine("Сумма всех веденных чисел: " + sum);
  28.                         break;
  29.                     default:
  30.                         nums.Add(Convert.ToInt32(input));
  31.                         break;
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment