Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = new int[0];
- string userInput;
- string sum = "sum";
- string exit = "exit";
- bool isFillingArray = true;
- int newAddedNumber = 0;
- int resultAddition = 0;
- Console.WriteLine("Сначала наш массив будет пуст((.");
- for (int i = 0; i < numbers.Length; i++)
- {
- Console.Write(numbers[i] + " ");
- }
- Console.WriteLine($"\nДальше вам нужно выбрать что вы делаете. Первое - вы можете написать {sum} - и получить сумму написанных чисел, " +
- $"вы можете написать {exit} и программа завершися, либо продолжить заполнение массива(любой знак или слово будут " +
- $"добавлены в массив если это не {sum} или {exit}).");
- while (isFillingArray)
- {
- userInput = Console.ReadLine();
- if (userInput == sum)
- {
- for (int i = 0; i < numbers.Length; i++)
- {
- resultAddition += numbers[i];
- }
- Console.WriteLine($"Сумма массива - {resultAddition}.");
- }
- else if (userInput == exit)
- {
- isFillingArray = false;
- Console.WriteLine("Спасибо что работали с нами.");
- }
- else
- {
- newAddedNumber = int.Parse(userInput);
- int[] newEnlargedArray = new int[numbers.Length + 1];
- for (int i = 0; i < numbers.Length; i++)
- {
- newEnlargedArray[i] = numbers[i];
- Console.WriteLine(newEnlargedArray[i]);
- }
- newEnlargedArray[newEnlargedArray.Length - 1] = newAddedNumber;
- numbers = newEnlargedArray;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement