TargeTPoweR

Расширение массива

Mar 27th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Для_проверки
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] array = new int[0];
  14. Console.WriteLine("Здравствуйте, пожалуйста введите числа : ");
  15. Console.WriteLine("Для выхода наберите exit.");
  16. Console.WriteLine("Для получения суммы введённых чисел наберите sum.");
  17. while (true)
  18. {
  19. string userInput = Console.ReadLine();
  20. if (userInput == "exit")
  21. {
  22. Console.WriteLine("До свидания.");
  23. break;
  24. }
  25. else if (userInput == "sum")
  26. {
  27. int sum = 0;
  28. for (int i = 0; i < array.Length; i++)
  29. sum += array[i];
  30. Console.WriteLine("Сумма введённых чисел равна: " + sum);
  31. }
  32. else
  33. {
  34. int[] tempArray = new int[array.Length + 1];
  35. int number = Convert.ToInt32(userInput);
  36. tempArray[tempArray.Length - 1] = number;
  37. for (int i = 0; i < array.Length; i++)
  38. tempArray[i] = array[i];
  39. array = tempArray;
  40. }
  41. }
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment