C Implementation of Sequential/Linear search

Linear Search C Implementation      Linear Search C++ Implementation

/* sequential search or linear search */

#include<stdio.h>
#include<conio.h>
void main()
{
int a[30],i,n,m,pos=0;
clrscr();
printf(“Enter the total number of elements “);
scanf(“%d”,&m);
printf(“enter the array elements \n”);
for(i=0;i<m;i++)
{
printf(“enter the %d element “,i);
scanf(“%d”,&a[i]);
}
printf(“enter the value of the element to search “);
scanf(“%d”,&n);
for(i=0;i<m;i++)
{
if (n==a[i])
{
pos=i+1;
break;
}
}
if (pos>0)
printf(“the element is found at %d position \n”,pos);
else
printf(“element to be searched is not found\n”);
getch();
}

Linear Search C Implementation      Linear Search C++ Implementation

Number Of Visitors

0125654