fork download
  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4.  
  5. int linearSearch(int arr[], int target, int n)
  6. {
  7. for( int i = 0; i < n; i++ ) {
  8. if ( arr[i] == target) {
  9. return 1;
  10. }
  11. }
  12. return -1;
  13. }
  14.  
  15. int main()
  16. {
  17. int n,target;
  18. cin >> n >> target;
  19. int a[n];
  20. for(int i = 0;i<n;i++){
  21. cin >> a[i];
  22. }
  23.  
  24. int res = linearSearch(a, target, n);
  25. if(res==1) cout << "FOUND";
  26. else cout << "NOT FOUND";
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5284KB
stdin
6 36
12 3049 5394 123 36 -5
stdout
FOUND