Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSharpLight_HomeWork18
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = new int[0];
- int sum = 0;
- string exit = "exit";
- string userValue = "open";
- while (userValue != exit)
- {
- Console.WriteLine("Введите числа, сумму которых хотите получить. Для выведения суммы введите sum. Для выхода введите exit.");
- Console.WriteLine("Введите число: ");
- userValue = Console.ReadLine();
- if (userValue == "sum")
- {
- for (int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- }
- Console.WriteLine("Сумма всех чисел: " + sum);
- Console.ReadKey();
- sum = 0;
- }
- else if (userValue == exit)
- {
- Console.WriteLine("До свидания!");
- }
- else
- {
- int[] tempArray = new int[array.Length + 1];
- for (int i = 0; i < tempArray.Length - 1; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = Convert.ToInt32(userValue);
- array = tempArray;
- }
- Console.Clear();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement