-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8960 - Linear Search Recursive.c
70 lines (49 loc) · 1.61 KB
/
8960 - Linear Search Recursive.c
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
59
60
61
62
63
64
65
66
67
68
69
70
/**********************************************************************************************************
NAME: CANDIDA RUTH NORONHA
CLASS: SE COMPS B
ROLL NO. : 8960
BATCH: C
TITLE: LINEAR SEARCH RECURSIVE ALGORITHM
SUBMISSION DATE : 22nd February, 2021
**********************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
int linearSearchRecursive(int a[],int n,int ele)
{
if(n==0)
return -1;
else if(a[n-1]==ele)
return n;
else
return(linearSearchRecursive(a,n-1,ele));
}
int main()
{
int a[SIZE], i, n,ele;
printf("\n Enter the number of elements in the array : ");
scanf("%d",&n);
printf("\n Enter the elements of the array : ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Enter the element to search : ");
scanf("%d",&ele);
printf("\n %d is present at location %d",ele,linearSearchRecursive(a,n,ele));
printf("\n");
return 0;
}
/**********************************************************************************************************
OUTPUT :
TEST CASE 1:
Enter the number of elements in the array : 6
Enter the elements of the array : 20 5 17 18 27 31
Enter the element to search : 18
18 is present at location 4
TEST CASE 2:
Enter the number of elements in the array : 4
Enter the elements of the array : 2 18 27 17
Enter the element to search : 10
10 is present at location -1
**********************************************************************************************************/