0/// Welcome criticism
1#include <stdio.h>2 3 inta[ -];4 5 intSearchintStartintEndDoubledistinction) {6 intmid;7 if(Distinction > A[end-1])8 returnEnd-1;9 if(Distinction <A[start])Ten returnstart; One while(1){ AMid = (start + end)/2; - if(A[mid-1] < distinction && A[mid] >distinction) - return((A[mid]-distinction) >= (Distinction-a[mid-1])) ? Mid-1: Mid; the if(Distinction > A[mid]) {///(A[start] + a[end])/2.0 > -Start =mid; -}Else if(Distinction <A[mid]) { -End =mid; +}Else{ - returnmid; + } A } at } - intMainvoid){ - intN; - Doublem; -printf"number of input array elements: \ n"); -scanf"%d",&n); in for(inti =0; I < n; i++) -scanf"%d",&a[i]); to while(SCANF ("%LF", &m)! =0){ +printf"%d\n", Search (0, N,m)); - } the * return 0; $}
Finds the position of the nearest number in the array with the target number (which can be a floating-point type)