Learn How Linier Search Method Works

Algorithm of Linier Search

Step 1: START = 0
FOUND = 0
Step 2: Repeat Step3 while START < N
Step 3: If A [START] = X then
FOUND=1
Break (Comes out from Loop)
Else
START=START + 1
Step 4: If FOUND = 1 then
Write “Search is Successful”
Else
Write “Search is Unsuccessful”

     

Program of Linier Search

#include<stdio.h>
#include<conio.h>
#define N 5
void main()
{
int a[N]={10,20,30,40,50};
int x;
void linier(int *a,int x);
clrscr();
printf("Enter Element to Search:");
scanf("%d",&x);
linier(a,x);
getch();
}
void linier(int *a,int x)
{
int START=0;
int FOUND=0;
while(START<N)
{
if(a[START]==x)
{
FOUND=1;
break;
}
else
{
START=START+1;
}
}
if (FOUND==1)
printf("Element is Found");
else
printf("Element Not Found");
}

Download Projects


Download Programs