编辑代码

#include <stdio.h>
#include <string.h>
#include <math.h>

int findElement (int a[], int x) {
	int l = 0, r = 6;
   	while (l < r) {
       int mid = (l + r)/ 2;
       if (a[mid] > x)  l = mid + 1;
       else  r = mid;
	}
	if (a[l] == x) return l;
	return -1;
}
int main() {
	
	int a[] = {85, 63, 52, 34, 25, 17, 6};
	int x = 6; 
	
	int i = findElement (a, x);
	if (i == -1) printf("元素不存在");
	else printf("元素存在,下标为%d\n", i); 
    return 0;
}