Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 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. namespace ConsoleApp2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. bool continue = true;
  13. while (continue)
  14. {
  15.  
  16.  
  17. {
  18. int wybor1;
  19.  
  20. Console.WriteLine("1. Tablice");
  21. Console.WriteLine("2. Stos");
  22. wybor1 = Int32.Parse(Console.ReadLine());
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. switch (wybor1)
  31. {
  32. case 1:
  33.  
  34. int roztab;
  35. Console.WriteLine("Podaj rozmiar tablicy");
  36. while (!int.TryParse(Console.ReadLine(), out roztab))
  37. Console.WriteLine("Zła liczba");
  38. Console.WriteLine("");
  39. int[] tablica = new int[roztab];
  40. int elemtab;
  41. Console.WriteLine("Podaj elementy tablicy");
  42. while (!int.TryParse(Console.ReadLine(), out elemtab))
  43. Console.WriteLine("Zła liczba");
  44.  
  45. Random rand = new Random();
  46. for (int i = 0; i < elemtab; i++)
  47. {
  48.  
  49. tablica[i] = rand.Next(0, 100);
  50. }
  51. Console.WriteLine("");
  52. for (int i = 0; i < roztab; i++)
  53. {
  54. Console.WriteLine(i + "." + tablica[i]);
  55. }
  56. Console.WriteLine("");
  57. int szukbi = 0;
  58. int szukliczb;
  59. Console.WriteLine("Podaj szukaną wartość");
  60. while (!int.TryParse(Console.ReadLine(), out szukliczb))
  61. Console.WriteLine("Zła liczba");
  62. for (int i = 0; i < roztab; i++)
  63. {
  64. if (szukliczb == tablica[i])
  65. {
  66. Console.WriteLine("Istnieją wartości: ");
  67. Console.WriteLine(i + "." + tablica[i]);
  68. szukbi = szukbi + 1;
  69.  
  70. }
  71.  
  72. }
  73. if (szukbi == 0)
  74. {
  75. Console.WriteLine("Brak takiej liczby");
  76. }
  77. Console.WriteLine("");
  78. int dptab;
  79. Console.WriteLine("Podaj nr tablicy");
  80. while (!int.TryParse(Console.ReadLine(), out dptab))
  81. Console.WriteLine("Zła liczba");
  82.  
  83. int nowawart;
  84. Console.WriteLine("Podaj nową wartość");
  85. while (!int.TryParse(Console.ReadLine(), out nowawart))
  86. Console.WriteLine("Zła liczba");
  87. tablica[dptab] = nowawart;
  88.  
  89.  
  90. Console.WriteLine("");
  91. for (int i = 0; i < roztab; i++)
  92. {
  93. Console.WriteLine(i + "." + tablica[i]);
  94. }
  95. Console.WriteLine("");
  96. Console.WriteLine("Dodawanie");
  97. int dodbi = 0;
  98. for (int i = 0; i < roztab; i++)
  99. if (tablica[i] == 0)
  100. {
  101. int dptab1;
  102. Console.WriteLine("Podaj wartość do tablicy:");
  103. while (!int.TryParse(Console.ReadLine(), out dptab1))
  104. Console.WriteLine("Zła liczba");
  105. tablica[i] = dptab1;
  106. dodbi = dodbi + 1;
  107.  
  108. Console.WriteLine("");
  109. }
  110. if (dodbi == 0)
  111. {
  112. Console.WriteLine("Tablica jest pełna");
  113.  
  114. }
  115.  
  116. Console.WriteLine("");
  117. for (int i = 0; i < roztab; i++)
  118. {
  119. Console.WriteLine(tablica[i]);
  120. }
  121.  
  122. Console.WriteLine("");
  123. Console.WriteLine("Sortowanie liczb");
  124. for (int k = 1; k < tablica.Length; k++)
  125. for (int i = 0; i < tablica.Length - 1; i++)
  126. if (tablica[i] > tablica[i + 1])
  127. {
  128. int tmp = tablica[i];
  129. tablica[i] = tablica[i + 1];
  130. tablica[i + 1] = tmp;
  131. }
  132.  
  133.  
  134. Console.WriteLine("");
  135. for (int i = 0; i < roztab; i++)
  136. {
  137. Console.WriteLine(i + "." + tablica[i]);
  138. }
  139.  
  140.  
  141. Console.ReadKey();
  142.  
  143.  
  144.  
  145. break;
  146.  
  147. case 2:
  148.  
  149.  
  150.  
  151. int rozszto;
  152. Console.WriteLine("Podaj rozmiar stosu");
  153. while (!int.TryParse(Console.ReadLine(), out rozszto))
  154. Console.WriteLine("Zła liczba");
  155. Console.WriteLine("");
  156. int[] tablica2 = new int[rozszto];
  157. int elemt;
  158. Console.WriteLine("Podaj ilość elementu stosu");
  159. while (!int.TryParse(Console.ReadLine(), out elemt))
  160. Console.WriteLine("Zła liczba");
  161.  
  162. int cos;
  163. Random rand2 = new Random();
  164. for (int i = 0; i < elemt; i++)
  165. {
  166. cos = rozszto - i - 1;
  167. tablica2[cos] = rand2.Next(1, 100);
  168. }
  169.  
  170.  
  171. Console.WriteLine("");
  172. for (int i = 0; i < rozszto; i++)
  173. {
  174. Console.WriteLine(i + "." + tablica2[i]);
  175. }
  176. Console.WriteLine("");
  177.  
  178.  
  179.  
  180. // int dojakiejwart;
  181. //int cos2;
  182. // Console.WriteLine("Podaj do jakiego elementu stosu chcesz dojść");
  183. // while (!int.TryParse(Console.ReadLine(), out dojakiejwart))
  184. // Console.WriteLine("Zła liczba");
  185. // for (int c = 0; c < elemt; c++)
  186. // {
  187. // if (tablica2[c] == dojakiejwart)
  188. // {
  189. // for (int i = 0; i < rozszto; i++)
  190. // {
  191. // Console.WriteLine("");
  192. // tablica
  193. // Console.WriteLine("Wyciągnięto górne elementy");
  194. // Console.WriteLine(i + "." + tablica2[i]);
  195. // Console.WriteLine("");
  196.  
  197. // }
  198. // }
  199.  
  200. /// }
  201.  
  202.  
  203. Console.WriteLine("Dodawanie");
  204. int dodbi2 = 0;
  205. int elemt2 = rozszto - elemt;
  206. int coss;
  207. for (int i = 0; i < elemt; i++)
  208. if (tablica2[i] == 0)
  209. {
  210.  
  211.  
  212. int dpsz;
  213. Console.WriteLine("Podaj wartość:");
  214. while (!int.TryParse(Console.ReadLine(), out dpsz))
  215. Console.WriteLine("Zła liczba");
  216. coss = i;
  217.  
  218. tablica2[coss] = dpsz;
  219. dodbi2 = dodbi2 + 1;
  220.  
  221. Console.WriteLine("");
  222. }
  223. if (dodbi2 == 0)
  224. {
  225. Console.WriteLine("Tablica jest pełna");
  226.  
  227. }
  228.  
  229. Console.WriteLine("");
  230. for (int i = 0; i < rozszto; i++)
  231. {
  232. Console.WriteLine(i + "." + tablica2[i]);
  233. }
  234.  
  235.  
  236.  
  237.  
  238.  
  239. Console.ReadKey();
  240.  
  241.  
  242.  
  243. break;
  244.  
  245. default:
  246. break;
  247. }
  248.  
  249.  
  250. }
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. }
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement