2/23/2009

C Program To Find An Element In A Given Array Using Linear Search Technique


/* C Program To Find An Element In A Given Array Using Linear Search Technique */
#include<stdio.h>
#include<conio.h>
void main()
{
 int i,n,key,flag=0,a[10];
 clrscr();
  printf("Enter the number of element\n");
   scanf("%d",&n);
  printf("Enter the values\n");
  for(i=0;i<n;i++)
   scanf("%d",&a[i]);
  printf("Enter the key value\n");
   scanf("%d",&key);

  for(i=0;i<n;i++)
   if(a[i]==key)
    {
      flag=1;
      break;
    }
  if(flag)
   printf("%d Found at position=%d\n",key,i+1);
  else
   printf("%d Not found\n",key);
 getch();
}
Out Put:
C Program To Find An Element In A Given Array Using Linear Search Technique

No comments:

Post a Comment