Advertisement
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 Array_
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Вводите целые числа, программа их запомнит, " +
- "при наборе комманды sum, выдаст сумму этих чисел, " +
- "\nпри наборе exit, произойдет выход из программы");
- int[] array = new int[0];
- while (true)
- {
- string userInput = Console.ReadLine();
- if (userInput == "sum")
- {
- int sum = 0;
- for (int i = 0; i < array.Length; i++)
- sum += array[i];
- Console.WriteLine("Сумма: " + sum);
- }
- else if (userInput == "exit")
- {
- break;
- }
- else
- {
- int[] tempArray = new int[array.Length + 1];
- int someNumer = Convert.ToInt32(userInput);
- tempArray[tempArray.Length - 1] = someNumer;
- for (int i = 0; i < array.Length; i++)
- tempArray[i] = array[i];
- array = tempArray;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement