C Program For Searching element in Array (Linear Search)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[10],n,ele,pos,search=0;
clrscr();
printf("enter the value of n: ");
scanf("%d",&n);
printf("\nenter the values");
for(i=0;i<n;i++)
scanf("%d",&a[i]);

printf("\nelements inserted are:\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
printf("\nenter element to be searched:\n");
scanf("%d",&ele);

for(i=0;i<n;i++)
{
 if(a[i]==ele)
 {
  search=1;
  pos=i;
 }
}
if(search==1)
 printf("element %d is found at %d position\n",ele,pos+1);
else
 printf("element not found");

getch();
}


Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment