Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.

Conversation

Sejzz
Copy link

@Sejzz Sejzz commented Oct 22, 2023

I am creating a pull request for...

  • New algorithm
  • Update to an algorithm
  • Fix an error
  • Other - Describe below

@Manishmine
Copy link

//write a code for binary search in array
#include <stdio.h>
int main()
{
int low, high, middle, search, num[10]={1,2,3,4,5,6,7,8,9,10};

printf("Enter value to find : ");
scanf("%d", &search);

low = 0;
high = 10;
middle = (low+high)/2;

while(low<=high){
	if(num[middle] == search){
		printf("element %d was found at index %d", search, middle);
		break;
	}
	else if(num[middle]<search){
		low=middle+1;
	}
	else{
		high=middle-1;
	}
	middle= (low+high)/2;
}

if(low>high){
	printf("not found!!");
}

return 0;
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants