You are on page 1of 2

LINEAR SEARCHING ALGORITHM

INTRODUCTION:
ALGORITHM:
o
o
o
o
o

Initialize the array a[100]


declare the variables n and x
Give the inputs to the array
Get the searching element (x)
If a[i]==x then print the position of the searching element

PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
int array[100], n, x;
cout<<*********************************
<<This program is to implement linear search algorithm\n
<<*************************************
cout<<Enter how many numbers you are going to enter::;
cin>>n;
cout<<Now enter your elements ::\n;
for(int i=;i<=n;i++)
cin>>array[i];
cout<<Enter the number to be searched ::;
cin>>x;
for(int i=;i<=n;i++)
{
if(array[i]==x)
{
cout<<found at location::<<i <<endl;
break;
}
}
getch();
}

SAMPLE OUTPUT
**************************************...
This program is to implement linear search algorithm
**************************************
Enter how many numbers you are going to enter::5
Now enter your elements ::
1.1

1.2
1.3
1.4
1.5
Enter the number to be searched ::1.5
found at position ::5

You might also like