Cod sursa(job #2750856)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 13 mai 2021 14:08:19
Problema Cbinteractiv Scor Ascuns
Compilator c-64 Status done
Runda Marime 0.45 kb
#include <stdio.h>

int main() 
{
    int n;
    scanf("%d", &n);

    int from = 1, to = n;

    while(from < to)
    {
        int mid = (from + to) / 2;

        printf("? %d\n", mid);
        fflush(stdout);

        int answer;
        scanf("%d", &answer);

        if(answer == 1)
        {
            to = mid;
        }
        else
        {
            from = mid + 1;
        }
    }

    printf("! %d\n", from);
    fflush(stdout);

    return 0;
}