Advertisement
o91leg

Untitled

Mar 29th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 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. int[] tempArray = new int[array.Length + 1];
  16. Console.WriteLine("Команды: \nВведите sum для суммы чисел\nВведите sort для сортировки\nВведите exit для выхода\nВведите число:");
  17. comand = Console.ReadLine();
  18. if (comand == "sum" || comand == "sort" || comand == "exit")
  19. {
  20. userCommand = comand;
  21. }else tempArray[tempArray.Length - 1] = Convert.ToInt32(comand);
  22. for (int i = 0; i < array.Length; i++)
  23. {
  24. tempArray[i] = array[i];
  25. }
  26. array = tempArray;
  27. int sum = 0;
  28. switch (userCommand)
  29. {
  30. case "sum":
  31. for (int i = 0; i < array.Length; i++)
  32. {
  33. sum += array[i];
  34. }
  35. Console.WriteLine("Сумма элементов " + sum);
  36. userCommand = " ";
  37. break;
  38. case "sort":
  39. int buf;
  40. for (int i = 0; i < array.Length - 1; i++)
  41. {
  42. for (int j = i + 1; j < array.Length; j++)
  43. {
  44. if (array[i] > array[j])
  45. {
  46. buf = array[i];
  47. array[i] = array[j];
  48. array[j] = buf;
  49. }
  50. }
  51. }
  52. for (int i = 0; i < array.Length; i++)
  53. {
  54. Console.Write(array[i] + " ");
  55. }
  56. Console.WriteLine();
  57. userCommand = " ";
  58. break;
  59. case "exit":
  60. isWork = false;
  61. break;
  62. }
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement