-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearsearch.c
More file actions
37 lines (36 loc) · 819 Bytes
/
linearsearch.c
File metadata and controls
37 lines (36 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<stdio.h>
#include<conio.h>
void lins(int *,int,int);
int main()
{
int sz,*ptr,key,i;
printf("enter size of the array");
scanf("%d",&sz);
int arr[sz];
printf("enter elements in the array");
for(i=0;i<sz;i++)
scanf("%d",&arr[i]);
printf("\nyour entered elements...\n");
for(i=0;i<sz;i++)
printf("%d ",arr[i]);
printf("\nenter the search key element ");
scanf("%d",&key);
ptr=&arr[0];
lins(ptr,key,sz);
getch();
return 0;
}
void lins(int *ptr,int kie,int size)
{
int i;
for(i=0;i<size;i++)
{
if(kie==*(ptr+i))
{
printf("element found...at index %d ",i+1);
break;
}
}
if(i==size)
printf("\noppss...look like search element is not in array");
}