Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int a[20],n,x,k;
- cout<<"n=";
- cin>>n;
- cout<<"x=";
- cin>>x;
- for (int i=0;i<n;i++)
- {
- cout<<"a["<<i<<"]=";
- cin>>a[i];
- }
- int i=0;
- while (i<n)
- {
- k=(i+n-1)/2;
- if (a[k]==x)
- {
- cout<<"van";
- return 0;
- }
- else
- {
- if (x>a[k])
- {
- i=k+1;
- }
- else
- {
- n=k-1;
- }
- }
- }
- if (i>=n)
- {
- cout<<"nem volt";
- }
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement