0% found this document useful (0 votes)
18 views2 pages

Binary Recursive

Uploaded by

pop pee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Binary Recursive

Uploaded by

pop pee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Binary Search (Recurssion)

#include <stdio.h>

int binSearch(int a[],int l,int h,int x)

int mid;

if(l==h)

if(x==a[l])

return l;

else

return 0;

else

mid=(l+h)/2;

if(x==a[mid])

printf("The key element found at:%d",mid);

return mid;

else if(x<a[mid])

binSearch(a,l,mid-1,x);

else

{
binSearch(a,mid+1,h,x);

int main()

int key,val,n,l,h,i;

int arr[10];

printf("\n Enter the number of elements:");

scanf("%d",&n);

printf("\nEnter the elements:");

for(i=0;i<n;i++)

scanf("%d",&arr[i]);

printf("The elements are:\n");

for(i=0;i<n;i++)

printf("%d",arr[i]);

printf("Enter the key element to be searched:\n");

scanf("%d",&key);

val=binSearch(arr,0,n-1,key);

printf("The position is:%d",val);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy