Program for linear search.

/*********************************
WAP TO SEARCH ELEMENTS WITH
MULTIPLE OCCURANCE WITH POSITIONS
BY LINEAR SEARCH TECHNIQUE.
**********************************/
#include stdio.h
#include conio.h

void main()
{
int a[100],n,i,ele,pos[100],c=0;
clrscr();
printf("Enter size of array: ");
scanf("%d",&n);
printf("Enter %d elements: ",n);
for(i=0;i
{
scanf("%d",&a[i]);
}
printf("Enter Element to be Searched: ");
scanf("%d",&ele);
for(i=0;i
{
if(a[i]==ele)
{
pos[c]=i+1;
c++;
}
}
if(c==0)
{
printf("Element Not Found.");
}
else
{
printf("Elements Found at Positions:\n");
for(i=0;i
{
printf("%d\t",pos[i]);
}
}
getch();
}

No comments:

Post a Comment