Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int linearSearch(int nums[], int size, int item)
- {
- for (int i = 0; i < size; i++)
- if (nums[i] == item)
- return i;
- return -1;
- }
- int main(int argc, char** argv)
- {
- int nums[] = {45, 41, 12, 34, 80, 100, 95,17, 52};
- int n = sizeof(nums) /sizeof(int);
- cout << "size of nums = " << n;
- cout << "Searching for 95 = " << linearSearch(nums, n, 95);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement