//July 22, 2017#include <stdio.h>#defineLEN 15intMain () {intN; voidBinsearch (int* p,intN); intarr[len]={98, the, the, the, the, -, $, Wu, +, the, the, $, *, to, in}; printf ("Please enter the number you want to find: \ n"); scanf ("%d",&N); Binsearch (Arr,n); return 0;}voidBinsearch (int* p,intN) { intLow,high,mid; Low=0; High=len-1; while(low<=High ) {Mid= (Low+high)/2; if(p[mid]==N) {printf ("%d is the value of the%d element of the array (subscript starting from 0) \ n", N,mid); Break;//Note After the element is found, the loop is ended } Else if(p[mid]>n) Low = mid+1; ElseHigh = mid-1; } if(Low>high) printf ("There is no such number in the array");}
There are 15 numbers that are stored in an array from large to small, using the binary lookup method to find out that the number is the value of the first element of the array, and if the number is not in the array, the output "no this number"