# include & lt; Stdio. H>
Void main () {
Int a, [3].
//char c;
Int I, num, mid, flag, legal, m, n, top, bott;
Int sign=0;//said there was no find the digits
Num=0;
Printf (" please input array: ");
The scanf (" % d ", & amp; A [0]);
I=1;
While (I & lt; 3) {
The scanf (" % d ", & amp; A [I]);
If (a [I] Printf (" \ n the input number is less than a number on, please input again is greater than the value of a number: ");
}
The else
i++;
}
Printf (" input array is: ");
for(i=0; i <3; I++) {
Printf (" % d ", a [I]);
}
printf("\n");
Flag=1;
//mid=15/2;
Mid=0;
Top=0;
Bott=14;
Legal=0;
While (flag) {
char c;
Printf (" please enter a search number: ");
The scanf (" % d ", & amp; Num);
M=(num & lt; A [0]);
N=(num & gt; A, [2]).
If ((num & lt; A [0]) | | (num & gt; A [2]))//is outside the scope of this score
Legal=1;
Sign=0;
Top=0;
Bott=3;
While (sign==0 & amp; & (top & lt;=bott)) {
Mid=+ bott (top)/2;
If (num & gt; A (mids))
Top=mid + 1;
Else if (num & lt; A (mids))
Bott=mid - 1;
The else {
Printf (" % d is the first % d a element of the array of values ", num, mid);
break;
Sign=1;
}
}
if(! Sign | | legal==1)
Printf (" without this number, \ n ");
//char c;
Printf (" whether or not to input (Y/N) ");
The scanf (" % c ", & amp; C);
If (c=='Y')
Flag=1;
The else
flag=0;
}
}
Why every time I perform to "whether or not to enter", then I can't input, jump straight to flag=0, and then exit the cycle???????
CodePudding user response:
Please reply toCodePudding user response:
Printf (" whether or not to input (Y/N) ");fflush(stdin);//try to empty the keyboard input buffer
The scanf (" % c ", & amp; C);
CodePudding user response:
You give blocked the char cCodePudding user response: