#include<stdio.h> #define?? ?M 10 int main() { ?? ?int a[M] = { -12,0,6,16,23,56,80,100,110,115 }; ?? ?int n,low, mid, high, find; ?? ?low = 0; ?? ?high = M - 1; ?? ?find = 0; ?? ?printf("please input number:\n"); ?? ?scanf_s("%d",&n); ?? ?while (low <= high) ?? ?{ ?? ??? ?mid = (low + high) / 2; ?? ??? ?if (n == a[mid]) ?? ??? ?{ ?? ??? ??? ?find = 1; ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?else if (n > a[mid]) ?? ??? ??? ?low = mid + 1; ?? ??? ?else ?? ??? ??? ?high = mid - 1; ?? ?} ?? ?if (find == 1) ?? ??? ?printf("The index of %d is %d", n, mid); ?? ?else ?? ??? ?printf("These is not %d",n);
}
|