-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopy of 1.c.CPP
More file actions
58 lines (53 loc) · 833 Bytes
/
Copy of 1.c.CPP
File metadata and controls
58 lines (53 loc) · 833 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
void sort(int [],int);
int lsearch(int [],int,int);
void main()
{
clock_t start,end;
int n,a[20],key,i,r;
randomize();
clrscr();
l:n=rand()%20;
if(n<=1)
{
goto l;
}
for(i=0;i<n;i++)
{
a[i]=rand()%100;
}
printf("\nRandomized array elements \n");
for(i=0;i<n;i++)
{
printf(" %d",a[i]);
}
printf("\nenter key element to be searched\n");
scanf("%d",&key);
start=clock();
r=lsearch(a,n-1,key);
end=clock();
if(r==-1)
printf("\n%d not found",key);
else printf("\n%d found in position %d",key,r+1);
printf("\ntime required to execute=%ld",(end-start)/CLK_TCK);
getch();
}
int lsearch(int b[],int n,int k)
{
if(n>=0)
{
if(k==b[n])
{
return n;
}
else
{
n--;
lsearch(b,n,k);
}
}
else return (-1);
}