1#include <stdio.h>2#include <stdlib.h>3 4 intSearch (int*a,intkey)5{//binary finds the element of key in the order table, returns 0 if the return element subscript is found6 intlow=0, Mid; 7 intHigh= -; 8 while(low<=High )9 { TenMid= (Low+high)/2; One if(Key==a[mid])returnMid//find the Unknown origin element A Else if(Key<a[mid]) high=mid-1;//continue searching in the first half of the area - ElseLow=mid+1;//Find in the second half area - } the return 0;//not found - } - - voidMain () + { - int*A,key,i; + intb[ -]={0}; AA=b; atprintf"Please enter 20 integers from the largest to the smaller: \ n"); - for(i=1; i<= -; i++) - { -scanf"%d",&B[i]); - - } inprintf"\ n"); -printf"Please enter the number you are looking for: \ n"); toscanf"%d",&key); + - if(! Search (A,key)) printf ("the number you are looking for is not in the destination array! \ n"); the Elseprintf"The number you are looking for is:%d \ n", Search (A,key)); *}
The method of dichotomy of C language