Advertisement
inhuman_Arif

Array 2

Sep 29th, 2021
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int main()
  7. {
  8.     #ifndef ONLINE_JUDGE
  9.         freopen("input.txt", "r", stdin);
  10.         freopen("output.txt", "w", stdout);
  11.     #endif
  12.  
  13.     int tc;
  14.     cin >> tc;
  15.     int n;
  16.     cin >> n;
  17.     int arr[n];
  18.     for(int i=0;i<n;i++)
  19.         cin >> arr[i];
  20.     int c=1;
  21.     while(tc--)
  22.     {
  23.         int ques;
  24.         cin >> ques;
  25.         bool flag = false;
  26.         int ind;
  27.         for(int i=0;i<n;i++)
  28.         {
  29.             if(arr[i]==ques)
  30.             {
  31.                 flag = true;
  32.                 ind = i;
  33.                 break;
  34.             }
  35.         }
  36.         if(flag)
  37.             printf("%d is found at index %d\n",ques,ind);
  38.         else
  39.             printf("%d is not found in the array\n",ques);
  40.     }
  41.  
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement