Dimitar23308

Untitled

Nov 28th, 2025
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     srand(time(0));
  9.  
  10.     const int N = 25;      
  11.     int arr[N];          
  12.     bool taken[N] = {0};  
  13.     int checked = 0;      
  14.  
  15.  
  16.     cout << "ALL ARRRAY: ";
  17.     for (int i = 0; i < N; i++) {
  18.         arr[i] = rand() % 50 + 1;
  19.         cout << arr[i] << " ";
  20.     }
  21.     cout << "\n";
  22.  
  23.     int M;
  24.     cout << "ENTER M SERCHED: ";
  25.     cin >> M;
  26.  
  27.  
  28.     while (checked < N) {
  29.  
  30.         int index = rand() % N;  
  31.  
  32.        
  33.         if (taken[index]) {
  34.             continue;
  35.         }
  36.  
  37.        
  38.         taken[index] = true;
  39.         checked++;
  40.  
  41.         cout << "CHECKING " << index
  42.              << " STOJNONST " << arr[index] << "...\n";
  43.  
  44.        
  45.         if (arr[index] == M) {
  46.             cout << "=== FOUND! ===\n";
  47.             cout << "M = " << M << " IS AT INDEX " << index << "\n";
  48.             return 0;
  49.         }
  50.     }
  51.  
  52.    
  53.     cout << "=== NOT FOUND ===\n";
  54.     cout << "ALL ARE CHECKED " << N << " ELEMNTS.\n";
  55.  
  56.     system("pause");
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment