Sunday, 17 June 2012

Sequential search


#include<stdio.h>
#include<conio.h>
int seqsearch(int k[],int n,int target)
{
 int i=0;
 while(i<n)
 {
  if(target==k[i])
   return i;
  i++;
 }
 return (-1);
}
void main()
{
 int k[10],n,target,i;
 clrscr();
 printf("\n Enter the size of the array ");
 scanf("%d",&n);
 printf("\n Enter the array values ");
 for(i=0;i<n;i++)
  scanf("%d",&k[i]);
 printf("\n Enter the element to find ");
 scanf("%d",&target);
 printf("\n The element %d is found in %d position",target,seqsearch(k,n,target));
 getch();
}

No comments:

Post a Comment