Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int f2(int n)
- {
- int pocz=1;
- int kon=n/2;
- int plus1=0;
- int max=n;
- int user;
- while(1)
- {
- printf("Z przedzialu %d-%d?\n",pocz,kon);
- scanf("%d",&user);
- if(!user)
- {
- if(kon-pocz==0) return kon+1;
- kon*=2;
- pocz=1+kon/2;
- if((kon-pocz)%2==1) plus1=1;
- kon=(kon-(kon-pocz)/2)+plus1;
- plus1=0;
- if(kon>max) kon=max;
- if(kon-pocz==0) return kon;
- if(kon-pocz==1) kon=pocz;
- }
- else
- {
- if(kon-pocz==0) return kon;
- if(kon-pocz==1) kon=pocz;
- else
- {
- max=kon;
- if((kon+pocz)%2==1) plus1=1;
- kon=(kon-(kon-pocz)/2)+plus1;
- plus1=0;
- }
- }
- }
- }
- int main()
- {
- printf("Szukana wartosc to: %d\n",f2(10));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement