Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Для_проверки
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[0];
- Console.WriteLine("Здравствуйте, пожалуйста введите числа : ");
- Console.WriteLine("Для выхода наберите exit.");
- Console.WriteLine("Для получения суммы введённых чисел наберите sum.");
- while (true)
- {
- string userInput = Console.ReadLine();
- if (userInput == "exit")
- {
- Console.WriteLine("До свидания.");
- break;
- }
- else if (userInput == "sum")
- {
- int sum = 0;
- for (int i = 0; i < array.Length; i++)
- sum += array[i];
- Console.WriteLine("Сумма введённых чисел равна: " + sum);
- }
- else
- {
- int[] tempArray = new int[array.Length + 1];
- int number = Convert.ToInt32(userInput);
- tempArray[tempArray.Length - 1] = number;
- for (int i = 0; i < array.Length; i++)
- tempArray[i] = array[i];
- array = tempArray;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment