o91leg

Untitled

Mar 31st, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _2_Сshrp_L
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. bool isWork = true;
  10. int[] array = new int[0];
  11. string userCommand = " ";
  12. string comand = " ";
  13. while (isWork == true)
  14. {
  15. Console.WriteLine("Команды: \nВведите sum для суммы чисел\nВведите sort для сортировки\nВведите exit для выхода\nВведите число:");
  16. comand = Console.ReadLine();
  17. if (comand == "sum" || comand == "sort" || comand == "exit")
  18. {
  19. userCommand = comand;
  20. }
  21. int sum = 0;
  22. switch (userCommand)
  23. {
  24. case "sum":
  25. for (int i = 0; i < array.Length; i++)
  26. {
  27. sum += array[i];
  28. }
  29. Console.WriteLine("Сумма элементов " + sum);
  30. userCommand = " ";
  31. break;
  32. case "sort":
  33. int buf;
  34. for (int i = 0; i < array.Length - 1; i++)
  35. {
  36. for (int j = i + 1; j < array.Length; j++)
  37. {
  38. if (array[i] > array[j])
  39. {
  40. buf = array[i];
  41. array[i] = array[j];
  42. array[j] = buf;
  43. }
  44. }
  45. }
  46. for (int i = 0; i < array.Length; i++)
  47. {
  48. Console.Write(array[i] + " ");
  49. }
  50. Console.WriteLine();
  51. userCommand = " ";
  52. break;
  53. case "exit":
  54. isWork = false;
  55. break;
  56. default:
  57. int[] tempArray = new int[array.Length + 1];
  58. tempArray[tempArray.Length - 1] = Convert.ToInt32(comand);
  59.  
  60. for (int i = 0; i < array.Length; i++)
  61. {
  62. tempArray[i] = array[i];
  63. }
  64. array = tempArray;
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
Add Comment
Please, Sign In to add comment