Neon1x1st

Untitled

Feb 26th, 2022 (edited)
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace CSharpLight
  7. {
  8.     public static class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             int[] array = new int[0];
  13.             bool exit = false;
  14.             string text = "Sum - сумма введеных чисел\nExit - выход";
  15.             Console.WriteLine(text);
  16.  
  17.             while (exit == false)
  18.             {
  19.                 Console.Write("Введите число: ");
  20.                 string input = Console.ReadLine();
  21.  
  22.                 if (input.ToLower() == "sum")
  23.                 {
  24.                     int arraySum = 0;
  25.  
  26.                     for (int i = 0; i < array.Length; i++)
  27.                     {
  28.                         arraySum += array[i];
  29.                     }
  30.                     Console.WriteLine("Сумма: " + arraySum);
  31.                 }
  32.                 else if (input.ToLower() == "exit")
  33.                 {
  34.                     exit = true;
  35.                 }
  36.                 else if (int.TryParse(input, out int number))
  37.                 {
  38.                     int[] tempArray = new int[array.Length + 1];
  39.                     tempArray[tempArray.Length - 1] = int.Parse(input);
  40.  
  41.                     for (int i = 0; i < array.Length; i++)
  42.                     {
  43.                         tempArray[i] = array[i];
  44.                     }
  45.                     array = tempArray;
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment