1: #include<stdio.h>
2: #include<conio.h>
3: void main()
4: {
5: int a[15], n, i, x;
6: void search(int a[25], int n, int x);
7: clrscr();
8: printf("Enter the no of elements : ");
9: scanf("%d",&n);
10: printf("\nEnter the elements : ");
11: for(i=0;i<n;i++)
12: scanf("%d", &a[i]);
13: printf("\nEnter the search element : ");
14: scanf("%d", &x);
15: search(a, n, x);
16: getch();
17: }
18: void search(int a[25], int n, int x)
19: {
20: int i, j, s=0, count=0;
21: clrscr();
22: for(i=0;i<n;i++)
23: {
24: if(a[i]==x)
25: {
26: count++;
27: s=1;
28: printf("\n\t\ta[%d]", i);
29: }
30: }
31: if(s==0)
32: {
33: printf("\n\n\n\tThe element %d is not found", x);
34: }
35: else
36: {
37: printf("\n\n\nThe memory location of %d is given above", x);
38: printf("\n\n\nThe element %d is repeated for %d time(s)", x,
39: count);
40: }
41: }
Linear Search
Subscribe to:
Posts (Atom)
No comments:
Post a Comment