C Program For Linear Search

/*Linear Search*/
#include<stdio.h>
#include<conio.h>
void main()
{
 int key,i,a[10],n,flag=0;
 clrscr();
 printf("Enter the number of elements");
 scanf("%d",&n);
 printf("Enter array elements:");
 for(i=0;i<n;i++)
    scanf("%d",&a[i]);
 printf("Enter Search Element");
 scanf("%d",&key);

 for(i=0;i<n;i++)
    {
       if(a[i]==key)
  {
      printf("Search Element Is Found at Location %d",i+1);
      flag=1;
      return;
  }
    }
    if(flag==0)
    printf("Search Element is 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