EmbLogic's Blog

Linear Search

1 #include <stdio.h>
2 int flag=1;
3 int main()
4 {
5         int arr[5];
6         int i, key;
7         printf(“Enter Array:\n”);
8         for(i=0;i<5;i++)
9         {
10                 scanf(“%d”, &arr[i]);
11         }
12         printf(“Elements of array:\n”);
13         for(i=0;i<5;i++)
14         {
15                 printf(“Araray ->%d:%d\n”,i, arr[i]);
16         }
17         printf(“Enter Key element:\n”);
18         scanf(“%d”, &key);
19         for(i=0;i<5;i++)
20                 if (arr[i] == key)
21                 {
22                         printf(“key found\n”);
23                         flag=0;
24                 }
25
26                 if(flag)
27                 {
28                         printf(“key not found\n”);
29                 }
30
31 return 0;
16,1-8        Top

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>