Search This Blog

Translate

C program to search element in array and display its location

C  program to search element in array and display its location



#include
#include
void main()
{
 int n[10],i,ele,cnt=0;
 clrscr();
 for(i=0;i<10 br="" i=""> {
  printf("\n Enter the  %d element:",i);
  scanf("%d",&n[i]);
  }
  printf("\n Enter the element to search:");
  scanf("%d",&ele);
  for(i=0;i<10 br="" i="">  {
   if(n[i]==ele)
   {
     printf("\n Element found at location:%d",i+1);
     cnt++;
   }
  }
  if(cnt==0)
   printf("The entered element is not found ? ? ?");
  else
   printf("\n The occurences of the number is:%d",cnt);

 getch();
}

C Program example List

Google+ Badge