Advertisement
El_GEMMY

arraysession

Jul 30th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie();
  9.  
  10.     freopen("input.txt", "r", stdin);
  11.     freopen("output.txt", "w", stdout);
  12.  
  13.     // n = size
  14.     // arr = {..}
  15.     // x
  16.  
  17.     int n; cin >> n;
  18.     int arr[n];
  19.  
  20.     for(int i = 0; i < n; i++){
  21.         cin >> arr[i];
  22.     }
  23.  
  24.     int x; cin >> x;
  25.  
  26.     bool found = false;
  27.    
  28.     for(int i = 0; i < n; i++){
  29.         if(arr[i] == x){
  30.             found = true;
  31.             cout << i << endl;
  32.             break;
  33.         }
  34.     }
  35.  
  36.     if(not found)
  37.         cout << "NOT FOUND" << endl;
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement