Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 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 ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. try
  14. {
  15. Console.WriteLine("Podaj wartość x:");
  16. int x = int.Parse(Console.ReadLine());
  17. Console.WriteLine("Podaj wartość y:");
  18. int y = int.Parse(Console.ReadLine());
  19. Console.WriteLine("Podaj wartość z:");
  20. int z = int.Parse(Console.ReadLine());
  21.  
  22. string order = "";
  23.  
  24. Console.WriteLine("Jak posortować ?");
  25. Console.WriteLine("1. Sortowanie rosnące");
  26. Console.WriteLine("2. Sortowanie malejące");
  27.  
  28. ConsoleKeyInfo key = Console.ReadKey();
  29. if(key.Key == ConsoleKey.D1)
  30.  
  31. Console.WriteLine(order);
  32. Console.ReadKey();
  33. }
  34. catch (Exception ex)
  35. {
  36. Console.WriteLine("Błąd aplikacji: {0} - {1} |{2}", ex.Message);
  37. }
  38. }
  39. static string SortAsceding(int x, int y, int z)
  40. {
  41. try {
  42. string order = "Posortowane rosnąco: {0],{1},{2}";
  43.  
  44. if (x > y)
  45. {
  46. if (x > z)
  47. {
  48. if (y > z)
  49. {
  50. order = string.Format("{0},{1},{2}", z, y, x);
  51. }
  52. else
  53. {
  54. order = string.Format("{0},{1},{2}", y, z, x);
  55. }
  56.  
  57.  
  58. }
  59. else
  60. {
  61. order = string.Format("{0},{1},{2}", y, x, z);
  62. }
  63. }
  64.  
  65. else {
  66. if (y > z)
  67. {
  68. if (x > z)
  69. {
  70. order = string.Format("{0},{1},{2}", z, x, y);
  71. }
  72. else
  73. {
  74. order = string.Format("{0},{1},{2}", x, z, y);
  75. }
  76.  
  77.  
  78. }
  79. else
  80. {
  81. order = string.Format("{0},{1},{2}", x, y, z);
  82. }
  83.  
  84. return (order);
  85. }
  86. }
  87.  
  88. catch (Exception ex)
  89. {
  90. Console.WriteLine("Błąd aplikacji: {0} - {1} | {2}", ex.Message);}
  91. return null;
  92.  
  93. }
  94. static string SortDescending(int x, int y, int z)
  95. {
  96. try
  97. {
  98. string order = "Posortowane malejąco: {0],{1},{2}";
  99.  
  100. if (x > y)
  101. {
  102. if (x > z)
  103. {
  104. if (y > z)
  105. {
  106. order = string.Format("{0},{1},{2}", x, y, z);
  107. }
  108. else
  109. {
  110. order = string.Format("{0},{1},{2}", x, z, y);
  111. }
  112.  
  113.  
  114. }
  115. else
  116. {
  117. order = string.Format("{0},{1},{2}", z, x, y);
  118. }
  119. }
  120.  
  121. else
  122. {
  123. if (y > z)
  124. {
  125. if (x > z)
  126. {
  127. order = string.Format("{0},{1},{2}", y, x, z);
  128. }
  129. else
  130. {
  131. order = string.Format("{0},{1},{2}", y, z, x);
  132. }
  133.  
  134.  
  135. }
  136. else
  137. {
  138. order = string.Format("{0},{1},{2}", z, y, x);
  139. }
  140.  
  141. return (order);
  142. }
  143. }
  144.  
  145. catch (Exception ex)
  146. {
  147. Console.WriteLine("Błąd aplikacji: {0} - {1} | {2}", ex.Message);
  148. }
  149. return null;
  150.  
  151. }
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement