We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
#include
// Function to perform recursive linear search
int recursiveLinearSearch(int arr[], int key, int index, int size) {
// Base case: If the element is not found
if (index
return -
}
// Tf the current element matches the key, return the index
if (arr[index] == key) {
return index;
}
// Recursive case: Search in the rest of the array
return recursiveLinearSearch(arr, key, index + 1, size);
int main() {
int arr[19];
int key, result;
// Input elements from the user
printf("Enter 1¢ elements for the array:\n");
for (int i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
// Input the key to search
printf("Enter the element to search: ");
scanf("%d", &key);
// Perform the recursive linear search
result = recursiveLinearSearch(arr, key, 8, 10);
// Check the result and print the appropriate message
if (result != -1) {
printf("Element found at index %d\n", result);
} else {
printf("Element not found in the array\n");
return @;Enter 10 elements for the array:
on
12
13
c
15
a}
17
a)
19
yt)
Enter the element to search: 15
Element found at index 4St SU aT ee Ula ad 6 Pela See Ural ae cay |
int mid;
f(first > last){
erent Number") ;
mid = (first + last)
Ce COCO ESULDY
ar:
1o
i (arr[mid] > num){
At)
BinarySearch(arr, num, first, mid-1);
} a
COE e ee ee
oC mi ulerg
int arr[50],beg,mid,end,i,n,num;
Cente CUS
¢ Pau
ee
(eure er reese)
ui
( /Sarr[i]});
i
oo
end-n-1;
ance a
eeu en
Cre ce Cee a
cE Tohiven Array: 10
4
ed Sequence
33
Enter The Value To Search Using Binary Search: 18
Element Is At The Index: 4
...Program finished with exit code 0
Press ENTER to exit console.