Advertisement
Yurka21

hw array

Dec 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 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 ConsoleApp3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string userInput;
  14. int[] array = new int[0];
  15. int[] tempArray = new int[array.Length + 1];
  16. bool open = true;
  17. int sum = 0;
  18.  
  19. Console.WriteLine("для ввода символов нажмите - ввод");
  20. Console.WriteLine("для вывода суммы нажмите - сумма");
  21. Console.WriteLine("для вывода массива нажмите - массив");
  22. Console.WriteLine("для выхода - выход");
  23.  
  24. while (open)
  25. {
  26. userInput = Console.ReadLine();
  27. switch (userInput)
  28. {
  29. case "выход":
  30. open = false;
  31. break;
  32.  
  33. case "ввод":
  34. Console.WriteLine("введите символ");
  35.  
  36. for (int i = 0; i < array.Length; i++)
  37. {
  38. tempArray[i] = array[i];
  39. }
  40.  
  41. tempArray[tempArray.Length - 1] = Convert.ToInt32(Console.ReadLine());
  42. array = tempArray;
  43. break;
  44.  
  45. case "сумма":
  46. for (int i = 0; i < array.Length; i++)
  47. sum += array[i];
  48. Console.WriteLine("syma" + sum);
  49. break;
  50.  
  51. case "массив":
  52. Console.WriteLine("Массив");
  53. for (int i = 0; i < array.Length; i++)
  54. {
  55. Console.WriteLine(array[i]);
  56. }
  57. break;
  58. }
  59. }
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement