Cod sursa(job #1379487)
Utilizator | Data | 6 martie 2015 18:05:56 | |
---|---|---|---|
Problema | Cautare binara | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
using namespace std;
int main()
{
ifstream cin ("cautbin.in");
ofstream cout ("cautbin.out");
int li,ls,gasit=false,x,mij,V[1000];
cin>>li>>ls;
while(li<=ls)
{
mij=(li+ls)/2;
if(x==V[mij]) {gasit=true;break;}
else if(x<V[mij]) ls=mij-1;
else li=mij+1;}
if(gasit=true)
cout<<mij;
return 0;
}