Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int i,x,n=6;
- int T[]={1,2,3,6,8,9};
- cout<<"Jakiej liczby szukasz?"<<endl;
- cin>>x;
- T[n]=x;
- i=0;
- while(T[i]!=x) i++;
- if (i!=n) cout<<"tak";
- else cout<<"nie";
- return 0;
- }
- #include <iostream>
- using namespace std;
- int main()
- {
- int x,l=0,p,n=6,s;
- int T[]={1,2,3,4,5,6,7};
- p=n-1;
- cin>>x;
- while(p>=l)
- {
- s=(l+p)/2;
- if (T[s]!=x)
- if(T[s]<x)
- l=s+1;
- else p=s-1;
- else {cout<<"tak";
- break;}
- }
- if (p<l) cout<<"nie";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement