fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int T[20] = {3, 4, 5, 8, 11, 13, 19, 20, 23, 26, 29, 30, 31, 33, 34, 37, 38, 44, 45, 48};
  5. int x;
  6.  
  7. scanf("%d", &x);
  8.  
  9. int L = 0;
  10. int H = 19;
  11. int M = (L + H) / 2;
  12.  
  13. while ((L <= H) && (x != T[M])) {
  14. if (x < T[M]) {
  15. H = M - 1;
  16. } else {
  17. L = M + 1;
  18. }
  19. M = (L + H) / 2;
  20. }
  21.  
  22. if (x == T[M]) {
  23. printf("Found at %d\n", M + 1);
  24. } else {
  25. printf("Not found\n");
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5304KB
stdin
12
stdout
Not found