SHARE
TWEET

Untitled

a guest Oct 15th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top