#include <stdio.h>
#include <stdlib.h>
int BuscaBinaria(int v[], int inicio, int fim, int valor) {
int meio = (inicio + fim) / 2;
if (v[meio] == valor) return meio;
if (fim == inicio) return -1;
if (v[meio] > valor) return BuscaBinaria(v, inicio, meio - 1, valor);
return BuscaBinaria(v, inicio + 1, meio, valor);
}
int main() {
int tam, valor;
printf("Qual o tamanho do vetor: "); int v[tam], i;
printf("Informe os valores do vetor:\n"); for (i = 0; i < tam; i++) {
}
printf("Informe o numero a ser buscado: "); int k = BuscaBinaria(v, 0, tam - 1, valor);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBCdXNjYUJpbmFyaWEoaW50IHZbXSwgaW50IGluaWNpbywgaW50IGZpbSwgaW50IHZhbG9yKSB7CiAgICBpbnQgbWVpbyA9IChpbmljaW8gKyBmaW0pIC8gMjsKICAgIGlmICh2W21laW9dID09IHZhbG9yKSByZXR1cm4gbWVpbzsKICAgIGlmIChmaW0gPT0gaW5pY2lvKSByZXR1cm4gLTE7CiAgICBpZiAodlttZWlvXSA+IHZhbG9yKSByZXR1cm4gQnVzY2FCaW5hcmlhKHYsIGluaWNpbywgbWVpbyAtIDEsIHZhbG9yKTsKICAgIHJldHVybiBCdXNjYUJpbmFyaWEodiwgaW5pY2lvICsgMSwgbWVpbywgdmFsb3IpOwp9CgppbnQgbWFpbigpIHsKICAgIGludCB0YW0sIHZhbG9yOwogICAgcHJpbnRmKCJRdWFsIG8gdGFtYW5obyBkbyB2ZXRvcjogIik7CiAgICBzY2FuZigiJWQiLCAmdGFtKTsKICAgIGludCB2W3RhbV0sIGk7CiAgICBwcmludGYoIkluZm9ybWUgb3MgdmFsb3JlcyBkbyB2ZXRvcjpcbiIpOwogICAgZm9yIChpID0gMDsgaSA8IHRhbTsgaSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJnZbaV0pOwogICAgfQogICAgcHJpbnRmKCJJbmZvcm1lIG8gbnVtZXJvIGEgc2VyIGJ1c2NhZG86ICIpOwogICAgc2NhbmYoIiVkIiwgJnZhbG9yKTsKICAgIGludCBrID0gQnVzY2FCaW5hcmlhKHYsIDAsIHRhbSAtIDEsIHZhbG9yKTsKICAgIHByaW50ZigiJWQiLCBrKTsKfQ==