Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int n;
- int tablica[n];
- cout<<"ile tabletek?: ";
- cin>>n;
- for(int i = 0; i < n; i++){
- cin>>tablica[i];
- }
- cout << endl;
- int srodek, x, y, lewy = 0, prawy = 10;
- cout << "czego szukosz: "; cin >> y;
- while(lewy <= prawy){
- srodek = (lewy + prawy)/2;
- if( tablica[srodek] == y){
- cout << "pod tym jest: " << srodek << endl;
- }
- if( tablica[srodek] < y){
- lewy = srodek + 1;
- }
- else{
- prawy = srodek - 1;
- }
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement