2/23/2009

C Program To Find An Element In A Given Array With Its Position Using Linear Search Technique (Second Method)


/* C Program To Find An Element In A Given Array With Its Position Using Linear Search Technique (Second Method)*/
#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i,j=0,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)
    {
      printf("%d is present at position %d\n",key,i+1);
      j++;
      flag=1;
    }
  if(flag)
   {
   printf("%d exist %d times\n",key,j);

   }
  else
   printf("%d is not found\n",key);
 getch();
}
Out Put:
C Program To Find An Element In A Given Array With Its Position Using Linear Search Technique (Second Method)

No comments:

Post a Comment