C++ Programming Code Examples C++ > Sorting Searching Code Examples Simple Linear Search Program in C++ Simple Linear Search Program in C++ Linear search is also called sequential search Linear search is a method for searching a value within an array. It sequentially checks one by one of the arrays for the target element until a match is found or until all the elements have been searched of that array. Linear search sequentially checks one by one of the collection(from 0th position to end) for the search element. So It is called sequential search. #include <iostream> #include<conio.h> #include<stdlib.h> #define maxsize 5 using namespace std; int main() { int arr_search[maxsize], i, element; cout << "Simple C++ Linear Search Example - Array\n"; cout << "\nEnter " << maxsize << " Elements for Searching : " << endl; for (i = 0; i < maxsize; i++) cin >> arr_search[i]; cout << "\nYour Data :"; for (i = 0; i < maxsize; i++) { cout << "\t" << arr_search[i]; } cout << "\nEnter Element to Search : "; cin>>element; /* for : Check elements one by one - Linear */ for (i = 0; i < maxsize; i++) { /* If for Check element found or not */ if (arr_search[i] == element) { cout << "\nLinear Search : Element : " << element << " : Found : Position : " << i + 1 << ".\n"; break; } } if (i == maxsize) cout << "\nSearch Element : " << element << " : Not Found \n"; getch(); }