Last active
July 19, 2017 08:46
-
-
Save idoushiki/c8772619da1dbb6c335bdd7e1d42438e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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