fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6. int n;
  7. int array[n+1];
  8. for (int i=1;i<=n;i++)
  9. {
  10. cin >>array[i];
  11. }
  12.  
  13. int ele,p=1,loc=0;
  14. cin >> ele;
  15. while (loc==0 && p<=array[p])
  16. {
  17. if(ele==array[p])
  18. {
  19. loc=p;
  20. }
  21. p++;
  22. }
  23. if (loc==0)
  24.  
  25. cout<< ele<<"not in the array"<<endl;
  26. else
  27. cout<< loc<<"is the location of"<<ele<<endl;
  28.  
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5256KB
stdin
Standard input is empty
stdout
21994not in the array