Sequential Search

1. Algorithm:

Sequential Search: the simplest algorithm to search a dictionary for a given key is to test successively against each element.

This works correctly regardless of the order of the elements in the list. However, in the worst case all elements might have to be tested.


2. Source code:

using namespace std;
int a[100],n,x;
int Sequential_Search(int M[], int N, int X){
int k = 0;
while (M[k] != X && k < N)
if (k < N)
return k;
return 0;
void InputArray(){
cout<<"Input number of array: "; cin>>n;
for(int i=0;i<n;i++){
cout<<"a["<<i<<"]= "; cin>>a[i];
cout<<"Input number which want to search: "; cin>>x;
int main(){
cout<<"Position in Array: "<<Sequential_Search(a,n,x);
return 0;

3. Result: