Advertisement
RedFlys

CSharpLight HomeWork18

Oct 31st, 2020 (edited)
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CSharpLight_HomeWork18
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = new int[0];
  10.             int sum = 0;
  11.             string exit = "exit";
  12.             string userValue = "open";
  13.  
  14.             while (userValue != exit)
  15.             {
  16.                 Console.WriteLine("Введите числа, сумму которых хотите получить. Для выведения суммы введите sum. Для выхода введите exit.");
  17.  
  18.                 Console.WriteLine("Введите число: ");
  19.                 userValue = Console.ReadLine();
  20.  
  21.                 if (userValue == "sum")
  22.                 {
  23.                     for (int i = 0; i < array.Length; i++)
  24.                     {
  25.                         sum += array[i];
  26.                     }
  27.  
  28.                     Console.WriteLine("Сумма всех чисел: " + sum);
  29.                     Console.ReadKey();
  30.                     sum = 0;
  31.                 }
  32.                 else if (userValue == exit)
  33.                 {
  34.                     Console.WriteLine("До свидания!");
  35.                 }
  36.                 else
  37.                 {
  38.                     int[] tempArray = new int[array.Length + 1];
  39.  
  40.                     for (int i = 0; i < tempArray.Length - 1; i++)
  41.                     {
  42.                         tempArray[i] = array[i];
  43.                     }
  44.  
  45.                     tempArray[tempArray.Length - 1] = Convert.ToInt32(userValue);
  46.                     array = tempArray;
  47.                 }
  48.                 Console.Clear();
  49.             }
  50.             Console.ReadKey();
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement