Wednesday, 3 September 2014

Prog. for Searching

#include<stdio.h>
#include<conio.h>
main()
{
      int list[100],n,i,x,p;
     
printf("\n Enter size of the list....");
scanf("%d",&n);
printf("\n Enter the elements....\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("\n Enter the element to be search  ");
scanf("%d",&x);
for(i=0;i<n;i++)
  {
      if(list[i]==x)
        p=i+1;
  }
  if(p>0)
  printf("\n The list of the element %d is found at position %d",x,p);
  else      
  printf("\n The element %d is not found,TRY AGAIN",x);
getch();
}
                   
                                       
                                       
                                       
                                       
                                       
                                       

No comments:

Post a Comment

Note: only a member of this blog may post a comment.