You are on page 1of 1

1 #include <stdio.

h>
2 #include <stdlib.h>
3
4 int linear_search(int a[], int size, int n);
5
6 int main()
7 { int a[10], i,r,n;
8 printf("Enter 10 elements of the array\n");
9
10 for(i=0;i<10;i++)
11 {
12 scanf("%d", &a[i]);
13 }
14
15 printf("Enter the element to search for:");
16 scanf("%d", &n);
17
18 r=linear_search(a,10,n);
19
20 if(r!=0)
21 printf("Number is in the array, found in index %d\n", r);
22 else
23 printf("Element is in the array");
24 return 0;
25 }
26
27 int linear_search(int a[], int size, int n)
28 {
29 int i;
30 for(i=0;i<size;i++)
31 { if(a[i]==n)
32 return i;
33 }
34 return 0;
35 }
36

You might also like