Skip to content

Instantly share code, notes, and snippets.

@idoushiki
Last active July 19, 2017 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idoushiki/c8772619da1dbb6c335bdd7e1d42438e to your computer and use it in GitHub Desktop.
Save idoushiki/c8772619da1dbb6c335bdd7e1d42438e to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(void){
int l,h,k,x;
int a[]={1,5,12,34,999};
h=5;
l=0;
scanf("%d",&x);
while(l<=h){
k=(l+h)/2;
if(a[k]==x){
printf("%d は存在する",a[k]);
break;
}
else if(a[k]<x)l=k+1;
else if(a[k]>x)h=k-1;
}
if(l>h)printf("%dは存在しない",x);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment