二分查找
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> int fn(int * a,int n,int x) { int s=0,e=n-1; int mid; while(s<=e) { mid=(s+e)>>1; if(a[mid] == x) return mid; else if(a[mid] > x) e=mid-1; else s=mid+1; } return -1; } int main() { int i,a[10]; for(i=0;i<10;i++) { a[i]=i*2; } while(1) { scanf("%d",&i); printf("%d\n",fn(a,10,i)); } return 0; }