Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. srand(time(0));
  9.  
  10. const int N = 10001;
  11. int tab[N], ile, x, s=0, i=0;
  12.  
  13. cout << "Ile liczb wylosowac? (max 10000)\n";
  14. cin >> ile;
  15.  
  16. while (ile < 0 || ile > 10000)
  17. {
  18. cout << "Bledna liczba";
  19. cin >> ile;
  20. }
  21.  
  22. for (int i = 0; i < ile; i++)
  23. {
  24. tab[i] = (rand() % 100) + 0;
  25. }
  26.  
  27. for (int i = 0; i < ile; i++)
  28. {
  29. cout << tab[i] << " ";
  30. }
  31.  
  32. cout << "Jaka liczbe wyszukac?\n";
  33. cin >> x;
  34.  
  35. cout << "Wyszukiwanie bez wartownika\n";
  36. cout << "---------------------------\n";
  37.  
  38.  
  39. while (tab[i] != x && i<ile)
  40. {
  41. i++;
  42. }
  43.  
  44. if (tab[i] != x)
  45. {
  46. cout << "Nie ma w ciagu elementu" << x << " || Liczba porownan: " << endl << endl;
  47.  
  48. }
  49.  
  50. else
  51. {
  52. cout << "Szukany element ciagu znajduje sie na pozycji " << i+1 << " || Liczba porownan: " <<endl<<endl;
  53.  
  54. }
  55.  
  56. cout << "Wyszukiwanie z wartownikiem\n";
  57. cout << "---------------------------\n";
  58.  
  59. tab[ile+1] = x;
  60. i = 1;
  61.  
  62. while (tab[i] !=x)
  63. {
  64. i++;
  65. }
  66.  
  67. if (i == ile)
  68. {
  69. cout << "Nie ma w ciagu elementu" << x;
  70.  
  71. }
  72.  
  73. else
  74. {
  75. cout << "Szukany element ciagu znajduje sie na pozycji " << i + 1 << " || Liczba porownan: " << endl << endl;
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement