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 Homework_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[1];
- bool isActive = true;
- while (isActive)
- {
- Console.Write($"Введите 'sum' или {array.Length}-й элемент массива: ");
- string userInput = Console.ReadLine();
- if (userInput == "exit")
- {
- isActive = false;
- }
- else if (userInput == "sum")
- {
- Console.Clear();
- int sum = 0;
- for (int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- }
- Console.WriteLine($"Сумма всех элементов массива = {sum}");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- int[] tempArray = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = Convert.ToInt32(userInput);
- array = tempArray;
- Console.Clear();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement