Advertisement
Guest User

people at gamedev.net are retarded

a guest
Mar 3rd, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. /*
  2. =================
  3. Linearsearch.cpp
  4. - A program implementing the linear search technique
  5. =================
  6. */
  7. #include<iostream>
  8. using namespace std;
  9. define SIZE 10 //define the constant SIZE
  10.  
  11. /*
  12. =================
  13. main function
  14. - main program
  15. =================
  16. */
  17. int main()
  18. {
  19.     int our_array[SIZE] = {55, 11, 22, 19, 71, 48, 37, 90, 211, 5};
  20.     int position, search_value;
  21.     cout << endl << "Please enter the value to search for: ";
  22.     cin >> search_value;
  23.     /* linear search algorithm */
  24.     for(int i = 0; i <= SIZE - 1; i++)
  25.     {
  26.         if(our_array[i] == search_value)
  27.         {
  28.             position = i;
  29.             break;
  30.         }
  31.         else
  32.             position = -1;
  33.         }
  34.  
  35.     if(position == -1)
  36.         cout << "The value searched for was not found" << endl;
  37.     else
  38.         cout << search_value << " found at position: " << position << endl;
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement