Advertisement
Ash_HeLiX

6

Oct 15th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 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 Home6
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string message = " ";
  14. bool isSum = false;
  15. int arraySum = 0;
  16. int[] array = new int[0];
  17. int stepSort = 1;
  18. int tempSort;
  19.  
  20.  
  21. do
  22. {
  23. message = Console.ReadLine();
  24. switch (message)
  25. {
  26. case "sum":
  27. for (int i = 0; i < array.Length; i++)
  28. {
  29. arraySum += array[i];
  30. }
  31. isSum = true;
  32. break;
  33. default:
  34. int[] tempArray = new int[array.Length + 1];
  35. for (int i = 0; i < array.Length; i++)
  36. {
  37. tempArray[i] = array[i];
  38. }
  39. tempArray[tempArray.Length-1] = Convert.ToInt32(message);
  40. array = tempArray;
  41. break;
  42. }
  43. } while (isSum != true);
  44. Console.WriteLine(arraySum);
  45.  
  46. for (int i = 0; i < array.Length; i++)
  47. {
  48. Console.Write(array[i] + " ");
  49. }
  50.  
  51. Console.WriteLine();
  52. while (stepSort != 0)
  53. {
  54. stepSort = 0;
  55. for (int i = 0; i < array.Length - 1; i++)
  56. {
  57. if (array[i] < array[i + 1])
  58. {
  59. tempSort = array[i];
  60. array[i] = array[i + 1];
  61. array[i + 1] = tempSort;
  62. stepSort++;
  63. }
  64. }
  65. }
  66.  
  67. for (int i = 0; i < array.Length; i++)
  68. {
  69. Console.Write(array[i] + " ");
  70. }
  71. Console.WriteLine();
  72.  
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement