Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(0));
- const int N = 10001;
- int tab[N], ile, x, s=0, i=0;
- cout << "Ile liczb wylosowac? (max 10000)\n";
- cin >> ile;
- while (ile < 0 || ile > 10000)
- {
- cout << "Bledna liczba";
- cin >> ile;
- }
- for (int i = 0; i < ile; i++)
- {
- tab[i] = (rand() % 100) + 0;
- }
- for (int i = 0; i < ile; i++)
- {
- cout << tab[i] << " ";
- }
- cout << "Jaka liczbe wyszukac?\n";
- cin >> x;
- cout << "Wyszukiwanie bez wartownika\n";
- cout << "---------------------------\n";
- while (tab[i] != x && i<ile)
- {
- i++;
- }
- if (tab[i] != x)
- {
- cout << "Nie ma w ciagu elementu" << x << " || Liczba porownan: " << endl << endl;
- }
- else
- {
- cout << "Szukany element ciagu znajduje sie na pozycji " << i+1 << " || Liczba porownan: " <<endl<<endl;
- }
- cout << "Wyszukiwanie z wartownikiem\n";
- cout << "---------------------------\n";
- tab[ile+1] = x;
- i = 1;
- while (tab[i] !=x)
- {
- i++;
- }
- if (i == ile)
- {
- cout << "Nie ma w ciagu elementu" << x;
- }
- else
- {
- cout << "Szukany element ciagu znajduje sie na pozycji " << i + 1 << " || Liczba porownan: " << endl << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement