Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int v[100],n,i,aux,j,x;
- cout<<"n=";cin>>n;
- cout<<"x=";cin>>x;
- for (i=0;i<n;i++)
- cin>>v[i];
- for (i=0;i<n-1;i++)
- for (j=i+1;j<n;j++)
- if (v[j]<v[i])
- {
- aux=v[j];
- v[j]=v[i];
- v[i]=aux;
- }
- int li=0,ls=n-1,mij,ok=0;
- while (li<=ls&&!ok)
- {
- mij=(li+ls)/2;
- if (x==v[mij])
- {
- cout<<"EXISTA";
- ok=1;
- }
- else
- if (x<v[mij])
- ls=mij-1;
- else
- li=mij+1;
- }
- if (!ok)
- cout<<"NU EXISTA";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement