Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int linearSearch(int nums[], int size, int item)
  5. {
  6. for (int i = 0; i < size; i++)
  7. if (nums[i] == item)
  8. return i;
  9. return -1;
  10. }
  11.  
  12.  
  13. int main(int argc, char** argv)
  14. {
  15. int nums[] = {45, 41, 12, 34, 80, 100, 95,17, 52};
  16. int n = sizeof(nums) /sizeof(int);
  17. cout << "size of nums = " << n;
  18. cout << "Searching for 95 = " << linearSearch(nums, n, 95);
  19. return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement