Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 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. namespace ConsoleApp26
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int[] array = new int[1];
  13.             string stroke;
  14.             bool isWork = true;
  15.             int summ = 0;
  16.             Console.WriteLine("Введите числа или команду\n summ - Найти сумму введёных чисел\n exit - выход из программы");
  17.             while (isWork)
  18.             {
  19.                 int[] tempArray = new int[array.Length + 1];
  20.                 for (int i = 0; i < array.Length; i++)
  21.                 {
  22.                     tempArray[i] = array[i];
  23.                 }
  24.                 stroke = Console.ReadLine();
  25.                 if (stroke == "exit")
  26.                 {
  27.                     isWork = false;
  28.                 }
  29.                 else if (stroke == "summ")
  30.                 {
  31.                     for (int i = 0; i < array.Length; i++)
  32.                     {
  33.                         summ += array[i];
  34.                     }
  35.                     Console.WriteLine("Сумма равна");
  36.                     Console.WriteLine(summ);
  37.                 }
  38.                 else
  39.                 {
  40.                     tempArray[tempArray.Length - 1] = Convert.ToInt32(stroke);
  41.                 }
  42.                 array = tempArray;
  43.                 summ = 0;
  44.             }
  45.             Console.ReadKey();
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement