Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp5
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = true;
- int[] array = new int[0];
- int sum = 0;
- while (exit)
- {
- Console.WriteLine("Заполните массив любыми цифрами.\n Как только вы напишите sum программа посчитает сумму ваших чисел.\n Как только вы напишите EXIT программа завершиться.");
- string command = Console.ReadLine().ToLower();
- switch (command)
- {
- case "exit":
- exit = false;
- break;
- case "sum":
- Console.WriteLine("Сумма массива:");
- for(int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i]+" ");
- }
- for (int i = 0; i < array.Length; i++)
- {
- sum +=array[i];
- }
- Console.WriteLine($"\nРавна = {sum}");
- Console.ReadLine();
- break;
- default:
- int[] arrayExtensions = new int[array.Length + 1];
- arrayExtensions[array.Length] = Convert.ToInt32(command);
- for (int i = 0; i < array.Length; i++)
- {
- arrayExtensions[i] = array[i];
- }
- array = arrayExtensions;
- break;
- }
- Console.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement