Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- =================
- Linearsearch.cpp
- - A program implementing the linear search technique
- =================
- */
- #include<iostream>
- using namespace std;
- define SIZE 10 //define the constant SIZE
- /*
- =================
- main function
- - main program
- =================
- */
- int main()
- {
- int our_array[SIZE] = {55, 11, 22, 19, 71, 48, 37, 90, 211, 5};
- int position, search_value;
- cout << endl << "Please enter the value to search for: ";
- cin >> search_value;
- /* linear search algorithm */
- for(int i = 0; i <= SIZE - 1; i++)
- {
- if(our_array[i] == search_value)
- {
- position = i;
- break;
- }
- else
- position = -1;
- }
- if(position == -1)
- cout << "The value searched for was not found" << endl;
- else
- cout << search_value << " found at position: " << position << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement