Advertisement
Rehan_Rahman26

//array problem 2

Sep 29th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. //array problem 2
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n,key,c=0,index;
  7.     cin >> n >> key;
  8.  
  9.     int ar[n];
  10.     for(int i=0; i<n; i++)
  11.     {
  12.         cin >> ar[i];
  13.         if(ar[i] == key)
  14.             c++;
  15.             index=i;
  16.     }
  17.     if(c>0)
  18.         cout << key << " is found in " << index << "index" << endl;
  19.         else cout << key << " is not found in the array"  << endl;
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement